;;; tex-info.el --- Support for editing Texinfo source.
-;; Copyright (C) 1993, 1994, 1997, 2000, 2001, 2004, 2005, 2006, 2011
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1997, 2000, 2001, 2004, 2005, 2006,
+;; 2011-2015, 2017 Free Software Foundation, Inc.
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex
;;; Code:
+(eval-when-compile (require 'cl))
+
(require 'tex)
(require 'texinfo)
(goto-char beg)
(TeX-activate-region) )))
+(defun Texinfo-nodename-de-escape (node-name)
+ "In NODE-NAME, convert `@comma{}' commands to the corresponding `,'
+character. Return the resulting string."
+ (let ((pos 0) (map '(("comma" . ","))))
+ (while (and (< pos (length
+ node-name)) (string-match "@\\(comma\\)[[:blank:]]*{}" node-name pos))
+ (setq node-name (concat (substring node-name 0 (match-beginning 0))
+ (cdr (TeX-assoc-string (match-string 1 node-name) map))
+ (substring node-name (match-end 0)))
+ pos (1+ (match-beginning 0)))))
+ node-name)
+
+
+(defun Texinfo-nodename-escape (node-name)
+ "Convert in NODE-NAME the `,' characters to `@comma{}'
+commands. Return the resulting string."
+ (let* ((pos 0)
+ (map '(("," . "comma")))
+ (re (regexp-opt (mapcar 'car map))) )
+ (while (and (< pos (length node-name)) (string-match re node-name pos))
+ (setq node-name (concat (substring node-name 0 (match-beginning 0))
+ "@" (cdr (TeX-assoc-string (match-string 0 node-name) map))
+ "{}"
+ (substring node-name (match-end 0)))
+ pos (1+ (match-beginning 0)))))
+ node-name)
+
+
+(defun Texinfo-make-node-list ()
+ ;; Build list of nodes in current buffer.
+ ;; (What about using `imenu--index-alist'?)
+ ;; FIXME: Support multi-file documents.
+ (save-excursion
+ (goto-char (point-min))
+ (let (nodes dups)
+ (while (re-search-forward "^@node\\b" nil t)
+ (skip-chars-forward "[:blank:]")
+ (pushnew (list (Texinfo-nodename-de-escape
+ (buffer-substring-no-properties
+ (point) (progn (skip-chars-forward "^\r\n,")
+ (skip-chars-backward "[:blank:]")
+ (point)))))
+ nodes
+ :test (lambda (a b)
+ (when (equal a b)
+ (push (cons a (TeX-line-number-at-pos (point))) dups)
+ t))))
+ (when dups
+ (display-warning
+ 'AUCTeX
+ (format "There are duplicate nodes:\n%s"
+ (mapconcat (lambda (dup)
+ (format " %s on line %d" (car dup) (cdr dup)))
+ (nreverse dups)
+ "\n"))))
+ (nreverse nodes))))
+
(defun Texinfo-insert-node ()
"Insert a Texinfo node in the current buffer.
That means, insert the string `@node' and prompt for current,
for @node."
(interactive)
(let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
- nodes node-name next-node previous-node up-node)
- ;; Build list of nodes in current buffer.
- ;; (What about using `imenu--index-alist'?)
- ;; FIXME: Support multi-file documents.
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward "^@node\\b" nil t)
- (skip-chars-forward " \t")
- (add-to-list 'nodes
- (list (buffer-substring-no-properties
- (point) (progn (skip-chars-forward "^,")
- (point)))))))
+ (nodes (Texinfo-make-node-list))
+ node-name next-node previous-node up-node)
(unless active-mark
- (setq node-name (read-string "Node name: ")))
+ (setq node-name (Texinfo-nodename-escape
+ (TeX-read-string "Node name: "))))
;; FIXME: What if key binding for `minibuffer-complete' was changed?
;; `substitute-command-keys' doesn't return the correct value.
- (setq next-node (completing-read "Next node (TAB completes): " nodes))
+ (setq next-node (Texinfo-nodename-escape
+ (completing-read "Next node (TAB completes): " nodes)))
(setq previous-node
- (completing-read "Previous node (TAB completes): " nodes))
- (setq up-node (completing-read "Upper node (TAB completes): " nodes))
+ (Texinfo-nodename-escape
+ (completing-read "Previous node (TAB completes): " nodes)))
+ (setq up-node (Texinfo-nodename-escape
+ (completing-read "Upper node (TAB completes): " nodes)))
(when (and active-mark
(< (mark) (point)))
(exchange-point-and-mark))
(progn (skip-chars-forward "^,") (forward-char 2))
(throw 'break nil)))))))
+(defun Texinfo-arg-nodename (optional &optional prompt definition)
+ "Prompt for a node name completing with known node names.
+OPTIONAL is ignored.
+Use PROMPT as the prompt string.
+If DEFINITION is non-nil, then chosen node name is a node name to be
+added to the list of defined node names. Current implementation
+ignored DEFINITION as the full document is scanned for node names at
+each invocation."
+ (let ((node-name (completing-read (TeX-argument-prompt optional prompt "Node")
+ (Texinfo-make-node-list))))
+ (insert "{" (Texinfo-nodename-escape node-name) "}" )))
+
+(defun Texinfo-arg-lrc (optional &rest args)
+ (let ((l (read-from-minibuffer "Enter left part: "))
+ (c (read-from-minibuffer "Enter center part: "))
+ (r (read-from-minibuffer "Enter right part: ")))
+ (insert " " l " @| " c " @| " r)))
+
+(defun Texinfo-arg-next-line (optional &rest args)
+ "Go to the beginning of next line if we are at the end of line. Otherwise insert an end-of-line."
+ (if (eolp) (forward-line) (insert "\n")))
+
+(defun Texinfo-arg-on|off (optional &optional prompt style)
+ "Prompt for a boolean input.
+OPTIONAL is ignored.
+Use PROMPT as the prompt string.
+STYLE may be one of `:on|off' or `:true|false', if omitted `:on|off'
+is assumed by default."
+(let ((collection (cdr (assq style
+ '((nil . #1=("on" "off"))
+ (:on|off . #1#)
+ (:true|false "true" "false"))))))
+ (insert (if (y-or-n-p (TeX-argument-prompt optional prompt (concat (car collection) ", not " (cadr collection))))
+ (car collection)
+ (cadr collection)))))
+
+(defun Texinfo-arg-choice (optional &optional prompt collection)
+ (insert (completing-read (TeX-argument-prompt optional prompt "Key")
+ collection)))
+
;; Silence the byte-compiler from warnings for variables and functions declared
;; in reftex.
-(eval-when-compile
- (defvar reftex-section-levels-all)
- (defvar reftex-level-indent)
- (defvar reftex-label-menu-flags)
- (defvar reftex-tables-dirty)
+(defvar reftex-section-levels-all)
+(defvar reftex-level-indent)
+(defvar reftex-label-menu-flags)
+(defvar reftex-tables-dirty)
+(eval-when-compile
(when (fboundp 'declare-function)
(declare-function reftex-match-string "reftex" (n))
(declare-function reftex-section-number "reftex-parse" (&optional level star))
(interactive)
(kill-all-local-variables)
(setq TeX-mode-p t)
+ (setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
(setq TeX-sentinel-default-function 'TeX-TeX-sentinel)
;; Mostly stolen from texinfo.el
(setq TeX-base-mode-name "Texinfo")
(set (make-local-variable 'require-final-newline) t)
(set (make-local-variable 'indent-tabs-mode) nil)
(set (make-local-variable 'paragraph-separate)
- (concat "\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
+ (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
(set (make-local-variable 'paragraph-start)
- (concat "\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
+ (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
(set (make-local-variable 'fill-column) 72)
(set (make-local-variable 'comment-start) "@c ")
(set (make-local-variable 'comment-start-skip) "@c +\\|@comment +")
(set (make-local-variable 'comment-use-syntax) nil)
(set (make-local-variable 'words-include-escapes) t)
- (if (boundp 'texinfo-imenu-generic-expression)
- ;; This was introduced in 19.30.
- (set (make-local-variable 'imenu-generic-expression) texinfo-imenu-generic-expression))
+ (set (make-local-variable 'imenu-generic-expression)
+ texinfo-imenu-generic-expression)
(set (make-local-variable 'font-lock-defaults)
;; COMPATIBILITY for Emacs 20
nil nil nil backward-paragraph
(font-lock-syntactic-keywords
. texinfo-font-lock-syntactic-keywords))
- '(texinfo-font-lock-keywords t)))
- (if (not (boundp 'texinfo-section-list))
- ;; This was included in 19.31.
- ()
- (set (make-local-variable 'outline-regexp)
- (concat "@\\("
- (mapconcat 'car texinfo-section-list "\\>\\|")
- "\\>\\)"))
- (set (make-local-variable 'outline-level) 'texinfo-outline-level))
+ ;; This is for Emacs >= 23.3, when
+ ;; `texinfo-font-lock-syntactic-keywords' was removed.
+ '(texinfo-font-lock-keywords nil nil nil backward-paragraph)))
+
+ ;; Outline settings.
+ (set (make-local-variable 'outline-regexp)
+ (concat "@\\("
+ (mapconcat 'car texinfo-section-list "\\>\\|")
+ "\\>\\)"))
+ (set (make-local-variable 'outline-level) 'texinfo-outline-level)
;; Mostly AUCTeX stuff
(easy-menu-add Texinfo-mode-menu Texinfo-mode-map)
(set (make-local-variable 'TeX-font-replace-function) 'TeX-font-replace-macro)
(set (make-local-variable 'TeX-style-hook-dialect) :texinfo)
- (add-hook 'find-file-hooks (lambda ()
- (unless (file-exists-p (buffer-file-name))
- (TeX-master-file nil nil t))) nil t)
+ (add-hook 'find-file-hook (lambda ()
+ (unless (file-exists-p (buffer-file-name))
+ (TeX-master-file nil nil t)))
+ nil t)
(when (and (boundp 'add-log-current-defun-function)
(fboundp 'texinfo-current-defun-name))
(TeX-add-symbols
'("acronym" "Acronym")
+ '("allowcodebreaks" (TeX-arg-literal " ") (Texinfo-arg-on|off nil :true|false) (Texinfo-arg-next-line))
'("appendix" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("appendixsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("appendixsection" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("appendixsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("appendixsubsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("asis")
+ '("atchar" nil)
'("author" (TeX-arg-literal " ") (TeX-arg-free "Author"))
'("b" "Text")
'("bullet")
'("cite" "Reference")
'("clear" (TeX-arg-literal " ") (TeX-arg-free "Flag"))
'("code" "Sample code")
+ '("codequotebacktick" (TeX-arg-literal " ") (Texinfo-arg-on|off) (Texinfo-arg-next-line))
+ '("codequoteundirected" (TeX-arg-literal " ") (Texinfo-arg-on|off) (Texinfo-arg-next-line))
'("command" "Command")
'("comment" (TeX-arg-literal " ") (TeX-arg-free "Comment"))
'("contents")
'("defindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
'("dfn" "Term")
'("dmn" "Dimension")
+ '("documentlanguage" (TeX-arg-literal " ") (Texinfo-arg-choice "Language" ("ca" "cs" "de" "en" "es" "fr" "hu" "is" "it" "ja" "nb" "nl" "nn" "pl" "pt" "ru" "sr" "tr" "uk")) (Texinfo-arg-next-line))
+ '("documentencoding" (TeX-arg-literal " ") (Texinfo-arg-choice "Encoding" ("US-ASCII" "UTF-8" "ISO-8859-1" "ISO-8859-15" "ISO-8859-2" "koi8-r" "koi8-u")) (Texinfo-arg-next-line))
'("dots" nil)
'("emph" "Text")
'("email" "Email address")
'("equiv" nil)
'("error")
- '("evenfooting" Texinfo-lrc-argument-hook)
- '("evenheading" Texinfo-lrc-argument-hook)
- '("everyfooting" Texinfo-lrc-argument-hook)
- '("everyheading" Texinfo-lrc-argument-hook)
+ '("evenfooting" Texinfo-arg-lrc)
+ '("evenheading" Texinfo-arg-lrc)
+ '("everyfooting" Texinfo-arg-lrc)
+ '("everyheading" Texinfo-arg-lrc)
'("exdent" (TeX-arg-literal " ") (TeX-arg-free "Line of text"))
'("expansion" nil)
'("file" "Filename")
'("findex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
'("footnote" "Text of footnote")
'("footnotestyle" (TeX-arg-literal " ") (TeX-arg-free "Style"))
- '("group")
+ '("guillemetleft")
+ '("guillemetright")
+ '("guilsinglleft")
+ '("guilsinglright")
'("heading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
;; XXX: Would be nice with completion.
'("headings" (TeX-arg-literal " ") (TeX-arg-free "On off single double"))
'("kbd" "Keyboard characters")
'("key" "Key name")
'("kindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
+ '("LaTeX" nil)
'("lowersections" 0)
'("majorheading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("menu")
(TeX-arg-literal ", ") (TeX-arg-free "Previous")
(TeX-arg-literal ", ") (TeX-arg-free "Up"))
'("noindent")
- '("oddfooting" Texinfo-lrc-argument-hook)
- '("oddheading" Texinfo-lrc-argument-hook)
+ '("oddfooting" Texinfo-arg-lrc)
+ '("oddheading" Texinfo-arg-lrc)
'("page")
'("paragraphindent" (TeX-arg-literal " ") (TeX-arg-free "Indent"))
'("pindex" "Entry")
'("point" nil)
'("print")
'("printindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
- '("pxref" "Node name")
+ '("pxref" (Texinfo-arg-nodename "Node name"))
+ '("quotedblbase")
+ '("quotesinglbase")
'("r" "Text")
'("raisesections" 0)
- '("ref" "Node name")
+ '("ref" (Texinfo-arg-nodename "Node name"))
'("refill")
'("result")
'("samp" "Text")
'("sc" "Text")
'("section" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("set" (TeX-arg-literal " ") (TeX-arg-free "Flag"))
- ;; XXX: Would be nice with completion.
- '("setchapternewpage" (TeX-arg-literal " ") (TeX-arg-free "On off odd"))
+ '("setchapternewpage" (TeX-arg-literal " ") (Texinfo-arg-choice "On off odd" ("on" "off" "odd")) (Texinfo-arg-next-line))
'("setfilename" (TeX-arg-literal " ") (TeX-arg-free "Info file name"))
'("settitle" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("shortcontents")
'("unnumberedsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("unnumberedsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
'("unnumberedsubsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
+ '("url" "Link")
'("value" "Flag")
'("var" "Metasyntactic variable")
'("vindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
'("vskip" (TeX-arg-literal " ") (TeX-arg-free "Amount"))
'("w" "Text")
- '("xref" "Node name"))
+ '("xref" (Texinfo-arg-nodename "Node name")))
;; RefTeX plugging
(add-hook 'reftex-mode-hook 'Texinfo-reftex-hook)