(defmacro defcustom (var value doc &rest ignore)
`(defvar ,var ,value ,doc)))
-(eval-when-compile (require 'tex-mode))
+(eval-when-compile (require 'tex-mode) (require 'cl))
(defgroup texinfo nil
"Texinfo Mode"
;;; Code:
;;; Don't you dare insert any `require' calls at top level in this file--rms.
-(eval-when-compile (require 'cl)) ;; for ignore-errors
(defvar texinfo-section-list
'(("top" 1)
["Makeinfo buffer" makeinfo-buffer t]))
\f
+(defun texinfo-filter (section list)
+ (let (res)
+ (dolist (x list) (if (eq section (cadr x)) (push (car x) res)))
+ res))
+
+(defvar texinfo-chapter-level-regexp
+ (regexp-opt (texinfo-filter 2 texinfo-section-list))
+ "Regular expression matching just the Texinfo chapter level headings.")
+
;;; Texinfo mode
;;;###autoload
If the file has a `top' node, it must be called `top' or `Top' and
be the first node in the file.
+
Entering Texinfo mode calls the value of `text-mode-hook', and then the
value of `texinfo-mode-hook'."
- (make-local-variable 'page-delimiter)
- (setq page-delimiter
- (concat
- "^@node [ \t]*[Tt]op\\|^@\\("
- "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
- "\\)"))
+ (set (make-local-variable 'page-delimiter)
+ (concat
+ "^@node [ \t]*[Tt]op\\|^@\\("
+ texinfo-chapter-level-regexp
+ "\\)\\>"))
(make-local-variable 'require-final-newline)
(setq require-final-newline t)
(make-local-variable 'indent-tabs-mode)
;; Prevent filling certain lines, in addition to ones specified
;; by the user.
(let ((prevent-filling "^@\\(def\\|multitable\\)"))
- (make-local-variable 'auto-fill-inhibit-regexp)
- (if (null auto-fill-inhibit-regexp)
- (setq auto-fill-inhibit-regexp prevent-filling)
- (setq auto-fill-inhibit-regexp
- (concat "\\(" auto-fill-inhibit-regexp "\\)\\|\\("
- prevent-filling "\\)")))))
-
+ (set (make-local-variable 'auto-fill-inhibit-regexp)
+ (if (null auto-fill-inhibit-regexp)
+ prevent-filling
+ (concat "\\(" auto-fill-inhibit-regexp "\\)\\|\\("
+ prevent-filling "\\)")))))
\f
;;; Insert string commands
(save-excursion
(backward-sexp 1)
(looking-at macro))
- (error nil)))))
+ (scan-error nil)))))
t))
- (error nil)))
+ (scan-error nil)))
(defun texinfo-inside-env-p (env &optional bound)
"Non-nil if inside an environment matching the regexp @ENV."
(save-excursion
(and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
- (looking-at (concat "@" env)))))
+ (not (match-end 1)))))
(defun texinfo-insert-quote (&optional arg)
"Insert the appropriate quote mark for TeXinfo.
(if (or arg
(texinfo-inside-env-p "example\\>" top)
(texinfo-inside-env-p "lisp\\>" top)
- (texinfo-inside-macro-p "@code\\>" top)
- (texinfo-inside-macro-p "@samp\\>" top)
- (texinfo-inside-macro-p "@kbd\\>" top)
- (texinfo-inside-macro-p "@kbd\\>" top))
+ (texinfo-inside-macro-p "@\\(code\\|samp\\|kbd\\)\\>" top))
(self-insert-command (prefix-numeric-value arg))
(insert
(cond ((= (preceding-char) ?\\) ?\")
(save-excursion
(while (and (> depth 0)
(re-search-backward texinfo-environment-regexp nil t))
- (if (looking-at "@end")
- (setq depth (1+ depth))
- (setq depth (1- depth))))
- (looking-at texinfo-environment-regexp)
- (if (zerop depth)
- (setq string
- (buffer-substring (match-beginning 1)
- (match-end 1)))))
+ (setq depth (if (looking-at "@end") (1+ depth) (1- depth))))
+ (when (zerop depth)
+ ;; This looking-at is unnecessary since if depth==0,
+ ;; (looking-at "@end") has just failed, so the match data is still
+ ;; the one from re-search-backward -sm
+ ;; (looking-at texinfo-environment-regexp)
+ (setq string (match-string 1))))
(insert "@end ")
(if string (insert string "\n"))))