4
0

mastermenu.el 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; mastermenu.el --- Redefinition of texinfo-master-menu-list
  2. ;; Copyright 2006-2023 Free Software Foundation, Inc.
  3. ;; Author: Sergey Poznyakoff
  4. ;; Maintainer: [email protected]
  5. ;; Keywords: maint, tex, docs
  6. ;; This file is part of GNU tar.
  7. ;; GNU tar is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU tar is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This file redefines texinfo-master-menu-list so that it takes into
  19. ;; account included files.
  20. ;; Known bugs: @menu without previous sectioning command will inherit
  21. ;; documentation string from the previous menu. However, since such a
  22. ;; menu is illegal in a texinfo file, we can live with it.
  23. (require 'texinfo)
  24. (require 'texnfo-upd)
  25. (defun texinfo-master-menu-list-recursive (title)
  26. "Auxiliary function used by `texinfo-master-menu-list'."
  27. (save-excursion
  28. (let (master-menu-list)
  29. (while (re-search-forward "\\(^@menu\\|^@include\\)" nil t)
  30. (cond
  31. ((string= (match-string 0) "@include")
  32. (skip-chars-forward " \t")
  33. (let ((included-name (let ((start (point)))
  34. (end-of-line)
  35. (skip-chars-backward " \t")
  36. (buffer-substring start (point)))))
  37. (end-of-line)
  38. (let ((prev-title (texinfo-copy-menu-title)))
  39. (save-excursion
  40. (set-buffer (find-file-noselect included-name))
  41. (setq master-menu-list
  42. (append (texinfo-master-menu-list-recursive prev-title)
  43. master-menu-list))))))
  44. (t
  45. (setq master-menu-list
  46. (cons (list
  47. (texinfo-copy-menu)
  48. (let ((menu-title (texinfo-copy-menu-title)))
  49. (if (string= menu-title "")
  50. title
  51. menu-title)))
  52. master-menu-list)))))
  53. master-menu-list)))
  54. (defun texinfo-master-menu-list ()
  55. "Return a list of menu entries and header lines for the master menu,
  56. recursing into included files.
  57. Start with the menu for chapters and indices and then find each
  58. following menu and the title of the node preceding that menu.
  59. The master menu list has this form:
  60. \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
  61. \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
  62. ...\)
  63. However, there does not need to be a title field."
  64. (reverse (texinfo-master-menu-list-recursive "")))
  65. (defun make-master-menu ()
  66. "Create master menu in the first Emacs argument."
  67. (find-file (car command-line-args-left))
  68. (texinfo-master-menu nil)
  69. (save-buffer))
  70. ;;; mastermenu.el ends here