?? texnfo-upd.el
字號:
(setq new-menu-list (cons (cons (texinfo-copy-node-name) (prog1 "" (forward-line 1))) ;; Use following to insert section titles automatically. ;; (texinfo-copy-section-title)) new-menu-list))) (reverse new-menu-list)))(defun texinfo-menu-locate-entry-p (level search-end) "Find a node that will be part of menu for this section.First argument is a string such as \"section\" specifying the generalhierarchical level of the menu; second argument is a positionspecifying the end of the search.The function returns t if the node is found, else nil. It searchesforward from point, and leaves point at the beginning of the node.The function finds entries of the same type. Thus `subsections' and`unnumberedsubsecs' will appear in the same menu." (let ((case-fold-search t)) (if (re-search-forward (concat "\\(^@node\\).*\n" ; match node line "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any "\\|" ; or "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any (eval (cdr (assoc level texinfo-update-menu-same-level-regexps)))) search-end t) (goto-char (match-beginning 1)))))(defun texinfo-copy-node-name () "Return the node name as a string.Start with point at the beginning of the node line; copy the textafter the node command up to the first comma on the line, if any, andreturn the text as a string. Leaves point at the beginning of theline. If there is no node name, returns an empty string." (save-excursion (buffer-substring (progn (forward-word 1) ; skip over node command (skip-chars-forward " \t") ; and over spaces (point)) (if (search-forward "," (save-excursion (end-of-line) (point)) t) ; bound search (1- (point)) (end-of-line) (point)))))(defun texinfo-copy-section-title () "Return the title of the section as a string.The title is used as a description line in the menu when one does notalready exist.Move point to the beginning of the appropriate section line by goingto the start of the text matched by last regexp searched for, whichmust have been done by `texinfo-menu-locate-entry-p'." ;; could use the same re-search as in `texinfo-menu-locate-entry-p' ;; instead of using `match-beginning'; such a variation would be ;; more general, but would waste information already collected (goto-char (match-beginning 7)) ; match section name (buffer-substring (progn (forward-word 1) ; skip over section type (skip-chars-forward " \t") ; and over spaces (point)) (progn (end-of-line) (point))));;; Handling the old menu(defun texinfo-old-menu-p (beginning first) "Move point to the beginning of the menu for this section, if any.Otherwise move point to the end of the first node of this section.Return t if a menu is found, nil otherwise.First argument is the position of the beginning of the section in whichthe menu will be located; second argument is the position of the firstnode within the section.If no menu is found, the function inserts two newlines just before theend of the section, and leaves point there where a menu ought to be." (goto-char beginning) (if (not (re-search-forward "^@menu" first 'goto-end)) (progn (insert "\n\n") (forward-line -2) nil) t))(defun texinfo-incorporate-descriptions (new-menu-list) "Copy the old menu line descriptions that exist to the new menu.Point must be at beginning of old menu.If the node-name of the new menu is found in the old menu, insert theold description into the new entry.For this function, the new menu is a list made up of lists of dottedpairs in which the first element of the pair is the node name and thesecond element the description. The new menu is changed destructively.The old menu is the menu as it appears in the Texinfo file." (let ((new-menu-list-pointer new-menu-list) (end-of-menu (texinfo-menu-end))) (while new-menu-list (save-excursion ; keep point at beginning of menu (if (re-search-forward ;; Existing nodes can have the form ;; * NODE NAME:: DESCRIPTION ;; or ;; * MENU ITEM: NODE NAME. DESCRIPTION. ;; ;; Recognize both when looking for the description. (concat "\\* \\(" ; so only menu entries are found (regexp-quote (car (car new-menu-list))) "::" "\\|" ".*: " (regexp-quote (car (car new-menu-list))) "[.,\t\n]" "\\)" ) ; so only complete entries are found end-of-menu t) (setcdr (car new-menu-list) (texinfo-menu-copy-old-description end-of-menu)))) (setq new-menu-list (cdr new-menu-list))) (setq new-menu-list new-menu-list-pointer)))(defun texinfo-incorporate-menu-entry-names (new-menu-list) "Copy any old menu entry names to the new menu.Point must be at beginning of old menu.If the node-name of the new menu entry cannot be found in the oldmenu, do nothing.For this function, the new menu is a list made up of lists of dottedpairs in which the first element of the pair is the node name and thesecond element is the description (or nil).If we find an existing menu entry name, we change the first element ofthe pair to be another dotted pair in which the car is the menu entryname and the cdr is the node name.NEW-MENU-LIST is changed destructively. The old menu is the menu as itappears in the texinfo file." (let ((new-menu-list-pointer new-menu-list) (end-of-menu (texinfo-menu-end))) (while new-menu-list (save-excursion ; keep point at beginning of menu (if (re-search-forward ;; Existing nodes can have the form ;; * NODE NAME:: DESCRIPTION ;; or ;; * MENU ITEM: NODE NAME. DESCRIPTION. ;; ;; We're interested in the second case. (concat "\\* " ; so only menu entries are found "\\(.*\\): " (car (car new-menu-list)) "[.,\t\n]") end-of-menu t) (setcar (car new-menu-list) ; replace the node name (cons (buffer-substring (match-beginning 1) (match-end 1)) (car (car new-menu-list))))) (setq new-menu-list (cdr new-menu-list)))) (setq new-menu-list new-menu-list-pointer)))(defun texinfo-menu-copy-old-description (end-of-menu) "Return description field of old menu line as string.Point must be located just after the node name. Point left before description.Single argument, END-OF-MENU, is position limiting search." (skip-chars-forward "[:.,\t\n ]+") ;; don't copy a carriage return at line beginning with asterisk! ;; do copy a description that begins with an `@'! ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc. (if (and (looking-at "\\(\\w+\\|@\\)") (not (looking-at "\\(^\\* \\|^@end menu\\)"))) (buffer-substring (point) (save-excursion (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t) (forward-line -1) (end-of-line) ; go to end of last description line (point))) ""))(defun texinfo-menu-end () "Return position of end of menu, but don't move point.Signal an error if not end of menu." (save-excursion (if (re-search-forward "^@end menu" nil t) (point) (error "Menu does not have an end."))))(defun texinfo-delete-old-menu (beginning first) "Delete the old menu. Point must be in or after menu.First argument is position of the beginning of the section in whichthe menu will be located; second argument is the position of the firstnode within the section." ;; No third arg to search, so error if search fails. (re-search-backward "^@menu" beginning) (delete-region (point) (save-excursion (re-search-forward "^@end menu" first) (point))));;; Inserting new menu;; try 32, but perhaps 24 is better(defvar texinfo-column-for-description 32 "*Column at which descriptions start in a Texinfo menu.")(defun texinfo-insert-menu (menu-list node-name) "Insert formatted menu at point.Indents the first line of the description, if any, to the value oftexinfo-column-for-description.MENU-LIST has form: \(\(\"node-name1\" . \"description\"\) \(\"node-name2\" . \"description\"\) ... \)However, the description field might be nil.Also, the node-name field might itself be a dotted pair (call it P) ofstrings instead of just a string. In that case, the car of Pis the menu entry name, and the cdr of P is the node name." (insert "@menu\n") (while menu-list ;; Every menu entry starts with a star and a space. (insert "* ") ;; Insert the node name (and menu entry name, if present). (let ((node-part (car (car menu-list)))) (if (stringp node-part) ;; "Double colon" entry line; menu entry and node name are the same, (insert (format "%s::" node-part)) ;; "Single colon" entry line; menu entry and node name are different. (insert (format "%s: %s." (car node-part) (cdr node-part))))) ;; Insert the description, if present. (if (cdr (car menu-list)) (progn ;; Move to right place. (indent-to texinfo-column-for-description 2) ;; Insert description. (insert (format "%s" (cdr (car menu-list)))))) (insert "\n") ; end this menu entry (setq menu-list (cdr menu-list))) (insert "@end menu") (message "Updated \"%s\" level menu following node: %s ... " level node-name));;; Starting menu descriptions by inserting titles(defun texinfo-start-menu-description () "In this menu entry, insert the node's section title as a description. Position point at beginning of description ready for editing.Do not insert a title if the line contains an existing description.You will need to edit the inserted text since a useful descriptioncomplements the node name rather than repeats it as a title does." (interactive) (let (beginning end node-name title) (save-excursion (beginning-of-line) (if (search-forward "* " (save-excursion (end-of-line) (point)) t) (progn (skip-chars-forward " \t") (setq beginning (point))) (error "This is not a line in a menu!")) (cond ;; "Double colon" entry line; menu entry and node name are the same, ((search-forward "::" (save-excursion (end-of-line) (point)) t) (if (looking-at "[ \t]*[^ \t\n]+") (error "Descriptive text already exists.")) (skip-chars-backward ": \t") (setq node-name (buffer-substring beginning (point)))) ;; "Single colon" entry line; menu entry and node name are different. ((search-forward ":" (save-excursion (end-of-line) (point)) t) (skip-chars-forward " \t") (setq beginning (point)) ;; Menu entry line ends in a period, comma, or tab. (if (re-search-forward "[.,\t]" (save-excursion (forward-line 1) (point)) t) (progn (if (looking-at "[ \t]*[^ \t\n]+") (error "Descriptive text already exists.")) (skip-chars-backward "., \t") (setq node-name (buffer-substring beginning (point)))) ;; Menu entry line ends in a return. (re-search-forward ".*\n" (save-excursion (forward-line 1) (point)) t) (skip-chars-backward " \t\n") (setq node-name (buffer-substring beginning (point))) (if (= 0 (length node-name)) (error "No node name on this line.") (insert ".")))) (t (error "No node name on this line."))) ;; Search for node that matches node name, and copy the section title. (if (re-search-forward (concat "^@node[ \t]+" node-name ".*\n" ; match node line "\\(" "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any "\\|" ; or "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any "\\)?") nil t) (progn (setq title (buffer-substring ;; skip over section type (progn (forward-word 1) ;; and over spaces (skip-chars-forward " \t") (point)) (progn (end-of-line) (skip-chars-backward " \t") (point))))) (error "Cannot find node to match node name in menu entry."))) ;; Return point to the menu and insert the title.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -