aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2016-03-10 15:17:47 -0500
committerStefan Monnier2016-03-10 15:17:47 -0500
commitea626c72e590aa7a45fd26df42240854e4225cef (patch)
treea77cb9ca8274a0562f40c2acfae21c3b2fec6b8b
parentdda6201a972a344c3cf2f35e61511f2cd62670f2 (diff)
downloademacs-ea626c72e590aa7a45fd26df42240854e4225cef.tar.gz
emacs-ea626c72e590aa7a45fd26df42240854e4225cef.zip
* lisp/textmodes/tex-mode.el: Complete local envs. Use #'.
Use #' for function names. (latex-complete-envnames): Include existing environments in current buffer. (latex-insert-block): Use latex-complete-envnames. (tildify-foreach-ignore-environments): Declare.
-rw-r--r--lisp/textmodes/tex-mode.el76
1 files changed, 49 insertions, 27 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index 19aefc29b96..5b1bd6a05bc 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -343,7 +343,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
343(defun latex-imenu-create-index () 343(defun latex-imenu-create-index ()
344 "Generate an alist for imenu from a LaTeX buffer." 344 "Generate an alist for imenu from a LaTeX buffer."
345 (let ((section-regexp 345 (let ((section-regexp
346 (concat "\\\\" (regexp-opt (mapcar 'car latex-section-alist) t) 346 (concat "\\\\" (regexp-opt (mapcar #'car latex-section-alist) t)
347 "\\*?[ \t]*{")) 347 "\\*?[ \t]*{"))
348 (metasection-regexp 348 (metasection-regexp
349 (concat "\\\\" (regexp-opt latex-metasection-list t))) 349 (concat "\\\\" (regexp-opt latex-metasection-list t)))
@@ -373,7 +373,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
373 ;; Using sexps allows some use of matching {...} inside 373 ;; Using sexps allows some use of matching {...} inside
374 ;; titles. 374 ;; titles.
375 (forward-sexp 1) 375 (forward-sexp 1)
376 (push (cons (concat (apply 'concat 376 (push (cons (concat (apply #'concat
377 (make-list 377 (make-list
378 (max 0 (- i i0)) 378 (max 0 (- i i0))
379 latex-imenu-indent-string)) 379 latex-imenu-indent-string))
@@ -413,7 +413,8 @@ An alternative value is \" . \", if you use a font with a narrow period."
413(defvar latex-outline-regexp 413(defvar latex-outline-regexp
414 (concat "\\\\" 414 (concat "\\\\"
415 (regexp-opt (append latex-metasection-list 415 (regexp-opt (append latex-metasection-list
416 (mapcar 'car latex-section-alist)) t))) 416 (mapcar #'car latex-section-alist))
417 t)))
417 418
418(defun latex-outline-level () 419(defun latex-outline-level ()
419 (if (looking-at latex-outline-regexp) 420 (if (looking-at latex-outline-regexp)
@@ -544,7 +545,8 @@ An alternative value is \" . \", if you use a font with a narrow period."
544 (let* (;; 545 (let* (;;
545 ;; Names of commands whose arg should be fontified with fonts. 546 ;; Names of commands whose arg should be fontified with fonts.
546 (bold (regexp-opt '("textbf" "textsc" "textup" 547 (bold (regexp-opt '("textbf" "textsc" "textup"
547 "boldsymbol" "pmb") t)) 548 "boldsymbol" "pmb")
549 t))
548 (italic (regexp-opt '("textit" "textsl" "emph") t)) 550 (italic (regexp-opt '("textit" "textsl" "emph") t))
549 ;; FIXME: unimplemented yet. 551 ;; FIXME: unimplemented yet.
550 ;; (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t)) 552 ;; (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
@@ -566,7 +568,8 @@ An alternative value is \" . \", if you use a font with a narrow period."
566 '("linebreak" "nolinebreak" "pagebreak" "nopagebreak" 568 '("linebreak" "nolinebreak" "pagebreak" "nopagebreak"
567 "newline" "newpage" "clearpage" "cleardoublepage" 569 "newline" "newpage" "clearpage" "cleardoublepage"
568 "displaybreak" "allowdisplaybreaks" 570 "displaybreak" "allowdisplaybreaks"
569 "enlargethispage") t)) 571 "enlargethispage")
572 t))
570 (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)") 573 (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
571 ;; 574 ;;
572 ;; Miscellany. 575 ;; Miscellany.
@@ -649,7 +652,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
649(defvar tex-verbatim-environments 652(defvar tex-verbatim-environments
650 '("verbatim" "verbatim*")) 653 '("verbatim" "verbatim*"))
651(put 'tex-verbatim-environments 'safe-local-variable 654(put 'tex-verbatim-environments 'safe-local-variable
652 (lambda (x) (null (delq t (mapcar 'stringp x))))) 655 (lambda (x) (null (delq t (mapcar #'stringp x)))))
653 656
654(eval-when-compile 657(eval-when-compile
655 (defconst tex-syntax-propertize-rules 658 (defconst tex-syntax-propertize-rules
@@ -1128,34 +1131,36 @@ subshell is initiated, `tex-shell-hook' is run."
1128 (concat "[ \t]*\\(\\$\\$\\|" 1131 (concat "[ \t]*\\(\\$\\$\\|"
1129 "\\\\[][]\\|" 1132 "\\\\[][]\\|"
1130 "\\\\" (regexp-opt (append 1133 "\\\\" (regexp-opt (append
1131 (mapcar 'car latex-section-alist) 1134 (mapcar #'car latex-section-alist)
1132 '("begin" "label" "end" 1135 '("begin" "label" "end"
1133 "item" "bibitem" "newline" "noindent" 1136 "item" "bibitem" "newline" "noindent"
1134 "newpage" "footnote" "marginpar" 1137 "newpage" "footnote" "marginpar"
1135 "parbox" "caption")) t) 1138 "parbox" "caption"))
1139 t)
1136 "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t) 1140 "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t)
1137 "\\>\\)")) 1141 "\\>\\)"))
1138 (setq paragraph-separate 1142 (setq paragraph-separate
1139 (concat "[\f%]\\|[ \t]*\\($\\|" 1143 (concat "[\f%]\\|[ \t]*\\($\\|"
1140 "\\\\[][]\\|" 1144 "\\\\[][]\\|"
1141 "\\\\" (regexp-opt (append 1145 "\\\\" (regexp-opt (append
1142 (mapcar 'car latex-section-alist) 1146 (mapcar #'car latex-section-alist)
1143 '("begin" "label" "end" )) t) 1147 '("begin" "label" "end" ))
1148 t)
1144 "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline" 1149 "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
1145 "noindent" "newpage" "footnote" 1150 "noindent" "newpage" "footnote"
1146 "marginpar" "parbox" "caption")) 1151 "marginpar" "parbox" "caption"))
1147 "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)" 1152 "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
1148 "\\>\\)[ \t]*\\($\\|%\\)\\)")) 1153 "\\>\\)[ \t]*\\($\\|%\\)\\)"))
1149 (setq-local imenu-create-index-function 'latex-imenu-create-index) 1154 (setq-local imenu-create-index-function #'latex-imenu-create-index)
1150 (setq-local tex-face-alist tex-latex-face-alist) 1155 (setq-local tex-face-alist tex-latex-face-alist)
1151 (add-hook 'fill-nobreak-predicate 'latex-fill-nobreak-predicate nil t) 1156 (add-hook 'fill-nobreak-predicate #'latex-fill-nobreak-predicate nil t)
1152 (setq-local indent-line-function 'latex-indent) 1157 (setq-local indent-line-function #'latex-indent)
1153 (setq-local fill-indent-according-to-mode t) 1158 (setq-local fill-indent-according-to-mode t)
1154 (add-hook 'completion-at-point-functions 1159 (add-hook 'completion-at-point-functions
1155 'latex-complete-data nil 'local) 1160 #'latex-complete-data nil 'local)
1156 (setq-local outline-regexp latex-outline-regexp) 1161 (setq-local outline-regexp latex-outline-regexp)
1157 (setq-local outline-level 'latex-outline-level) 1162 (setq-local outline-level #'latex-outline-level)
1158 (setq-local forward-sexp-function 'latex-forward-sexp) 1163 (setq-local forward-sexp-function #'latex-forward-sexp)
1159 (setq-local skeleton-end-hook nil)) 1164 (setq-local skeleton-end-hook nil))
1160 1165
1161;;;###autoload 1166;;;###autoload
@@ -1205,6 +1210,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
1205 1210
1206(defvar tildify-space-string) 1211(defvar tildify-space-string)
1207(defvar tildify-foreach-region-function) 1212(defvar tildify-foreach-region-function)
1213(declare-function tildify-foreach-ignore-environments
1214 "tildify" (pairs callback _beg end))
1208(defvar tex--prettify-symbols-alist) 1215(defvar tex--prettify-symbols-alist)
1209 1216
1210(defun tex-common-initialization () 1217(defun tex-common-initialization ()
@@ -1216,7 +1223,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
1216 ;; rather than using regex-based filtering. 1223 ;; rather than using regex-based filtering.
1217 (setq-local tildify-foreach-region-function 1224 (setq-local tildify-foreach-region-function
1218 (apply-partially 1225 (apply-partially
1219 'tildify-foreach-ignore-environments 1226 #'tildify-foreach-ignore-environments
1220 `(("\\\\\\\\" . "") ; do not remove this 1227 `(("\\\\\\\\" . "") ; do not remove this
1221 (,(eval-when-compile 1228 (,(eval-when-compile
1222 (concat "\\\\begin{\\(" 1229 (concat "\\\\begin{\\("
@@ -1534,8 +1541,7 @@ a skeleton (see `skeleton-insert').")
1534Puts point on a blank line between them." 1541Puts point on a blank line between them."
1535 (let ((choice (completing-read (format "LaTeX block name [%s]: " 1542 (let ((choice (completing-read (format "LaTeX block name [%s]: "
1536 latex-block-default) 1543 latex-block-default)
1537 (append latex-block-names 1544 (latex-complete-envnames)
1538 latex-standard-block-names)
1539 nil nil nil nil latex-block-default))) 1545 nil nil nil nil latex-block-default)))
1540 (setq latex-block-default choice) 1546 (setq latex-block-default choice)
1541 (unless (or (member choice latex-standard-block-names) 1547 (unless (or (member choice latex-standard-block-names)
@@ -1592,17 +1598,32 @@ Puts point on a blank line between them."
1592 (complete-with-action action keys key pred))))) 1598 (complete-with-action action keys key pred)))))
1593 1599
1594(defun latex-complete-envnames () 1600(defun latex-complete-envnames ()
1595 (append latex-block-names latex-standard-block-names)) 1601 (completion-table-in-turn
1602 (append latex-block-names latex-standard-block-names)
1603 (completion-table-dynamic
1604 (lambda (str)
1605 (with-current-buffer (if (and (minibufferp) (minibuffer-selected-window))
1606 (window-buffer (minibuffer-selected-window))
1607 (current-buffer))
1608 (save-excursion
1609 (let ((comps '())
1610 (pos (point)))
1611 (goto-char (point-min))
1612 (while (re-search-forward (concat "\\\\begin{\\(" str "[^}\n ]*\\)")
1613 nil t)
1614 (unless (and (<= (match-beginning 0) pos)
1615 (>= (match-end 0) pos))
1616 (push (match-string 1) comps)))
1617 comps)))))))
1596 1618
1597(defun latex-complete-refkeys () 1619(defun latex-complete-refkeys ()
1598 (when (boundp 'reftex-docstruct-symbol) 1620 (when (boundp 'reftex-docstruct-symbol)
1599 (symbol-value reftex-docstruct-symbol))) 1621 (symbol-value reftex-docstruct-symbol)))
1600 1622
1601(defvar latex-complete-alist 1623(defvar latex-complete-alist
1602 ;; TODO: Add \begin, \end, \ref, ... 1624 `(("\\`\\\\\\(short\\)?cite\\'" . ,#'latex-complete-bibtex-keys)
1603 '(("\\`\\\\\\(short\\)?cite\\'" . latex-complete-bibtex-keys) 1625 ("\\`\\\\\\(begin\\|end\\)\\'" . ,#'latex-complete-envnames)
1604 ("\\`\\\\\\(begin\\|end\\)\\'" . latex-complete-envnames) 1626 ("\\`\\\\[vf]?ref\\'" . ,#'latex-complete-refkeys)))
1605 ("\\`\\\\[vf]?ref\\'" . latex-complete-refkeys)))
1606 1627
1607(defun latex-complete-data () 1628(defun latex-complete-data ()
1608 "Get completion-data at point." 1629 "Get completion-data at point."
@@ -2185,7 +2206,7 @@ of the current buffer."
2185 2206
2186(defun tex-summarize-command (cmd) 2207(defun tex-summarize-command (cmd)
2187 (if (not (stringp cmd)) "" 2208 (if (not (stringp cmd)) ""
2188 (mapconcat 'identity 2209 (mapconcat #'identity
2189 (mapcar (lambda (s) (car (split-string s))) 2210 (mapcar (lambda (s) (car (split-string s)))
2190 (split-string cmd "\\s-*\\(?:;\\|&&\\)\\s-*")) 2211 (split-string cmd "\\s-*\\(?:;\\|&&\\)\\s-*"))
2191 "&"))) 2212 "&")))
@@ -2367,7 +2388,8 @@ Only applies the FSPEC to the args part of FORMAT."
2367 ;; Substitute and return. 2388 ;; Substitute and return.
2368 (if (and hist-cmd 2389 (if (and hist-cmd
2369 (string-match (concat "[' \t\"]" (format-spec "%r" fspec) 2390 (string-match (concat "[' \t\"]" (format-spec "%r" fspec)
2370 "\\([;&' \t\"]\\|\\'\\)") hist-cmd)) 2391 "\\([;&' \t\"]\\|\\'\\)")
2392 hist-cmd))
2371 ;; The history command was already applied to the same file, 2393 ;; The history command was already applied to the same file,
2372 ;; so just reuse it. 2394 ;; so just reuse it.
2373 hist-cmd 2395 hist-cmd
@@ -2752,7 +2774,7 @@ Runs the shell command defined by `tex-show-queue-command'."
2752(defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>") 2774(defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>")
2753(defvar latex-noindent-environments '("document")) 2775(defvar latex-noindent-environments '("document"))
2754(put 'latex-noindent-environments 'safe-local-variable 2776(put 'latex-noindent-environments 'safe-local-variable
2755 (lambda (x) (null (delq t (mapcar 'stringp x))))) 2777 (lambda (x) (null (delq t (mapcar #'stringp x)))))
2756 2778
2757(defvar tex-latex-indent-syntax-table 2779(defvar tex-latex-indent-syntax-table
2758 (let ((st (make-syntax-table tex-mode-syntax-table))) 2780 (let ((st (make-syntax-table tex-mode-syntax-table)))