aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-10-01 00:30:52 +0000
committerStefan Monnier2000-10-01 00:30:52 +0000
commiteedd2812657ce6a083c8bc7ee6265e914bad9f69 (patch)
tree311d4e548d0e99a0bd0453b82da5ee2944505543
parentad03cafc90a13e2bda066cd0274371e369a71ee2 (diff)
downloademacs-eedd2812657ce6a083c8bc7ee6265e914bad9f69.tar.gz
emacs-eedd2812657ce6a083c8bc7ee6265e914bad9f69.zip
(texinfo-font-lock-syntactic-keywords):
Add regexp for @ignore ... @end ignore. (texinfo-heading-face): New face. (texinfo-font-lock-keywords): Use it. (texinfo-mode-menu): New menu. (texinfo-inside-macro-p, texinfo-inside-env-p, texinfo-insert-quote): New functions. (texinfo-mode-map): Bind " to insert-quote and M-RET to insert-@item. (texinfo-section-types-regexp, texinfo-section-level-regexp) (texinfo-subsection-level-regexp, texinfo-subsubsection-level-regexp): Remove declaration. (texinfo-show-structure): Use outline-regexp and texinfo-section-list.
-rw-r--r--lisp/textmodes/texinfo.el169
1 files changed, 96 insertions, 73 deletions
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 3a87b79e95e..20d4f73148e 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -243,6 +243,27 @@ chapter."
243 243
244;;; Don't you dare insert any `require' calls at top level in this file--rms. 244;;; Don't you dare insert any `require' calls at top level in this file--rms.
245 245
246(defvar texinfo-section-list
247 '(("top" 1)
248 ("majorheading" 1)
249 ("chapter" 2)
250 ("unnumbered" 2)
251 ("appendix" 2)
252 ("chapheading" 2)
253 ("section" 3)
254 ("unnumberedsec" 3)
255 ("appendixsec" 3)
256 ("heading" 3)
257 ("subsection" 4)
258 ("unnumberedsubsec" 4)
259 ("appendixsubsec" 4)
260 ("subheading" 4)
261 ("subsubsection" 5)
262 ("unnumberedsubsubsec" 5)
263 ("appendixsubsubsec" 5)
264 ("subsubheading" 5))
265 "Alist of sectioning commands and their relative level.")
266
246;;; Syntax table 267;;; Syntax table
247 268
248(defvar texinfo-mode-syntax-table nil) 269(defvar texinfo-mode-syntax-table nil)
@@ -267,15 +288,20 @@ chapter."
267(defvar texinfo-imenu-generic-expression 288(defvar texinfo-imenu-generic-expression
268 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1) 289 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
269 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1)) 290 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
270
271 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.") 291 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
272 292
273(defvar texinfo-font-lock-syntactic-keywords 293(defvar texinfo-font-lock-syntactic-keywords
274 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11)))) 294 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11)))
295 ("^\\(@\\)ignore\\>" (1 '(2097163)))
296 ("^@end ignore\\(\n\\)" (1 '(2097164))))
275 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.") 297 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
276 298
299(defface texinfo-heading-face
300 '((t (:inherit font-lock-function-name-face)))
301 "Face used for section headings in `texinfo-mode'.")
302
277(defvar texinfo-font-lock-keywords 303(defvar texinfo-font-lock-keywords
278 '(;; All but the first had an OVERRIDE of t. 304 `(;; All but the first had an OVERRIDE of t.
279 ;; It didn't seem to be any better, and it's slower--simon. 305 ;; It didn't seem to be any better, and it's slower--simon.
280 ;; Robert J. Chassell <bob@gnu.org> says remove this line. 306 ;; Robert J. Chassell <bob@gnu.org> says remove this line.
281 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) 307 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
@@ -287,30 +313,10 @@ chapter."
287 2 font-lock-variable-name-face) 313 2 font-lock-variable-name-face)
288 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face) 314 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
289 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep) 315 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
290 ) 316 (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list) t)
317 ".*\n") 0 texinfo-heading-face t))
291 "Additional expressions to highlight in TeXinfo mode.") 318 "Additional expressions to highlight in TeXinfo mode.")
292 319
293(defvar texinfo-section-list
294 '(("top" 1)
295 ("majorheading" 1)
296 ("chapter" 2)
297 ("unnumbered" 2)
298 ("appendix" 2)
299 ("chapheading" 2)
300 ("section" 3)
301 ("unnumberedsec" 3)
302 ("appendixsec" 3)
303 ("heading" 3)
304 ("subsection" 4)
305 ("unnumberedsubsec" 4)
306 ("appendixsubsec" 4)
307 ("subheading" 4)
308 ("subsubsection" 5)
309 ("unnumberedsubsubsec" 5)
310 ("appendixsubsubsec" 5)
311 ("subsubheading" 5))
312 "Alist of sectioning commands and their relative level.")
313
314(defun texinfo-outline-level () 320(defun texinfo-outline-level ()
315 ;; Calculate level of current texinfo outline heading. 321 ;; Calculate level of current texinfo outline heading.
316 (save-excursion 322 (save-excursion
@@ -354,9 +360,7 @@ chapter."
354 ;; bindings for `texnfo-tex.el' 360 ;; bindings for `texnfo-tex.el'
355 (texinfo-define-common-keys texinfo-mode-map) 361 (texinfo-define-common-keys texinfo-mode-map)
356 362
357 ;; Bindings from `tex-mode.el' 363 (define-key texinfo-mode-map "\"" 'texinfo-insert-quote)
358 ;; This should still use " when inside @example and @code
359 ;;(define-key texinfo-mode-map "\"" 'tex-insert-quote)
360 364
361 ;; bindings for `makeinfo.el' 365 ;; bindings for `makeinfo.el'
362 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation) 366 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
@@ -369,6 +373,9 @@ chapter."
369 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region) 373 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
370 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer) 374 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
371 375
376 ;; AUCTeX-like bindings
377 (define-key texinfo-mode-map "\e\r" 'texinfo-insert-@item)
378
372 ;; bindings for updating nodes and menus 379 ;; bindings for updating nodes and menus
373 380
374 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu) 381 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
@@ -382,7 +389,7 @@ chapter."
382 389
383 (define-key texinfo-mode-map "\C-c}" 'up-list) 390 (define-key texinfo-mode-map "\C-c}" 'up-list)
384 (define-key texinfo-mode-map "\C-c]" 'up-list) 391 (define-key texinfo-mode-map "\C-c]" 'up-list)
385 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces) 392 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
386 393
387 ;; bindings for inserting strings 394 ;; bindings for inserting strings
388 (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block) 395 (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block)
@@ -407,6 +414,26 @@ chapter."
407 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn) 414 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
408 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code)) 415 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
409 416
417(easy-menu-define texinfo-mode-menu
418 texinfo-mode-map
419 "Menu used for `texinfo-mode'."
420 '("Texinfo"
421 ["Insert block" texinfo-insert-block t]
422 ;; ["Insert node" texinfo-insert-@node t]
423 "----"
424 ["Update All" (lambda () (interactive) (texinfo-master-menu t)) t]
425 ["Update every node" texinfo-every-node-update t]
426 ["Update node" texinfo-update-node t]
427 ["Make Master menu" texinfo-master-menu t]
428 ["Make menu" texinfo-make-menu t]
429 ["Update all menus" texinfo-all-menus-update t]
430 "----"
431 ["Show structure" texinfo-show-structure t]
432 ["Format region" texinfo-format-region t]
433 ["Format buffer" texinfo-format-buffer t]
434 ["Makeinfo region" makeinfo-region t]
435 ["Makeinfo buffer" makeinfo-buffer t]))
436
410 437
411;;; Texinfo mode 438;;; Texinfo mode
412 439
@@ -609,6 +636,39 @@ Puts point on a blank line between them."
609 (completing-read "Block name: " (mapcar 'list texinfo-environments)) 636 (completing-read "Block name: " (mapcar 'list texinfo-environments))
610 "@" str \n _ \n "@end " str \n) 637 "@" str \n _ \n "@end " str \n)
611 638
639(defun texinfo-inside-macro-p (macro &optional bound)
640 "Non-nil if inside a macro matching the regexp MACRO."
641 (ignore-errors
642 (save-excursion
643 (save-restriction
644 (narrow-to-region bound (point))
645 (while (progn
646 (up-list -1)
647 (not (ignore-errors
648 (save-excursion
649 (backward-sexp 1)
650 (looking-at macro))))))
651 t))))
652
653(defun texinfo-inside-env-p (env &optional bound)
654 "Non-nil if inside an environment matching the regexp @ENV."
655 (save-excursion
656 (and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
657 (looking-at (concat "@" env)))))
658
659(autoload 'tex-insert-quote "tex-mode" nil t)
660(defun texinfo-insert-quote (&optional arg)
661 "Insert the appropriate quote mark for TeXinfo.
662Inserts a plain \" if inside @code or @example, else inserts `` or ''
663by calling `tex-insert-quote'."
664 (interactive "*P")
665 (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t))
666 (point-min))))
667 (if (or (texinfo-inside-env-p "example\\>" top)
668 (texinfo-inside-macro-p "@code\\>" top))
669 (self-insert-command (prefix-numeric-value arg))
670 (tex-insert-quote arg))))
671
612;; The following texinfo-insert-@end command not only inserts a SPC 672;; The following texinfo-insert-@end command not only inserts a SPC
613;; after the @end, but tries to find out what belongs there. It is 673;; after the @end, but tries to find out what belongs there. It is
614;; not very smart: it does not understand nested lists. 674;; not very smart: it does not understand nested lists.
@@ -771,12 +831,6 @@ The default is not to surround any existing words with the braces."
771 831
772;;; Texinfo file structure 832;;; Texinfo file structure
773 833
774;; These are defined in texnfo-upd.el. defvars here avoid warnings.
775(defvar texinfo-section-types-regexp)
776(defvar texinfo-section-level-regexp)
777(defvar texinfo-subsection-level-regexp)
778(defvar texinfo-subsubsection-level-regexp)
779
780(defun texinfo-show-structure (&optional nodes-too) 834(defun texinfo-show-structure (&optional nodes-too)
781 "Show the structure of a Texinfo file. 835 "Show the structure of a Texinfo file.
782List the lines in the file that begin with the @-sign commands for 836List the lines in the file that begin with the @-sign commands for
@@ -792,12 +846,11 @@ one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence]
792to jump to the corresponding spot in the Texinfo source file." 846to jump to the corresponding spot in the Texinfo source file."
793 847
794 (interactive "P") 848 (interactive "P")
795 (require 'texnfo-upd)
796 (save-excursion 849 (save-excursion
797 (goto-char (point-min)) 850 (goto-char (point-min))
798 (if nodes-too 851 (if nodes-too
799 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp)) 852 (occur (concat "^@node\\>\\|" outline-regexp))
800 (occur texinfo-section-types-regexp))) 853 (occur outline-regexp)))
801 (pop-to-buffer "*Occur*") 854 (pop-to-buffer "*Occur*")
802 (goto-char (point-min)) 855 (goto-char (point-min))
803 (let ((inhibit-read-only t)) 856 (let ((inhibit-read-only t))
@@ -805,41 +858,11 @@ to jump to the corresponding spot in the Texinfo source file."
805 ;; Now format the "*Occur*" buffer to show the structure. 858 ;; Now format the "*Occur*" buffer to show the structure.
806 ;; Thanks to ceder@signum.se (Per Cederqvist) 859 ;; Thanks to ceder@signum.se (Per Cederqvist)
807 (goto-char (point-max)) 860 (goto-char (point-max))
808 (let ((margin 5)) 861 (let (level)
809 (while (re-search-backward "^ *[0-9]*:" nil 0) 862 (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
810 (re-search-forward ":") 863 (goto-char (1- (match-beginning 1)))
811 (setq margin 864 (setq level (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
812 (cond 865 (indent-to-column (+ (current-column) (* 4 (- level 2))))
813 ((looking-at
814 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
815 ;; ((looking-at "@chapter ") 5)
816 ;; ((looking-at "@unnumbered ") 5)
817 ;; ((looking-at "@appendix ") 5)
818 ;; ((looking-at "@majorheading ") 5)
819 ;; ((looking-at "@chapheading ") 5)
820
821 ((looking-at
822 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
823 ;; ((looking-at "@section ") 9)
824 ;; ((looking-at "@unnumberedsec ") 9)
825 ;; ((looking-at "@appendixsec ") 9)
826 ;; ((looking-at "@heading ") 9)
827
828 ((looking-at
829 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
830 ;; ((looking-at "@subsection ") 13)
831 ;; ((looking-at "@unnumberedsubsec ") 13)
832 ;; ((looking-at "@appendixsubsec ") 13)
833 ;; ((looking-at "@subheading ") 13)
834
835 ((looking-at
836 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
837 ;; ((looking-at "@subsubsection ") 17)
838 ;; ((looking-at "@unnumberedsubsubsec ") 17)
839 ;; ((looking-at "@appendixsubsubsec ") 17)
840 ;; ((looking-at "@subsubheading ") 17)
841 (t margin)))
842 (indent-to-column margin)
843 (beginning-of-line))))) 866 (beginning-of-line)))))
844 867
845;;; The tex and print function definitions: 868;;; The tex and print function definitions: