1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-12 09:28:24 +00:00

* 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.
This commit is contained in:
Stefan Monnier 2016-03-10 15:17:47 -05:00
parent dda6201a97
commit ea626c72e5

View File

@ -343,7 +343,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
(defun latex-imenu-create-index ()
"Generate an alist for imenu from a LaTeX buffer."
(let ((section-regexp
(concat "\\\\" (regexp-opt (mapcar 'car latex-section-alist) t)
(concat "\\\\" (regexp-opt (mapcar #'car latex-section-alist) t)
"\\*?[ \t]*{"))
(metasection-regexp
(concat "\\\\" (regexp-opt latex-metasection-list t)))
@ -373,7 +373,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
;; Using sexps allows some use of matching {...} inside
;; titles.
(forward-sexp 1)
(push (cons (concat (apply 'concat
(push (cons (concat (apply #'concat
(make-list
(max 0 (- i i0))
latex-imenu-indent-string))
@ -413,7 +413,8 @@ An alternative value is \" . \", if you use a font with a narrow period."
(defvar latex-outline-regexp
(concat "\\\\"
(regexp-opt (append latex-metasection-list
(mapcar 'car latex-section-alist)) t)))
(mapcar #'car latex-section-alist))
t)))
(defun latex-outline-level ()
(if (looking-at latex-outline-regexp)
@ -544,7 +545,8 @@ An alternative value is \" . \", if you use a font with a narrow period."
(let* (;;
;; Names of commands whose arg should be fontified with fonts.
(bold (regexp-opt '("textbf" "textsc" "textup"
"boldsymbol" "pmb") t))
"boldsymbol" "pmb")
t))
(italic (regexp-opt '("textit" "textsl" "emph") t))
;; FIXME: unimplemented yet.
;; (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."
'("linebreak" "nolinebreak" "pagebreak" "nopagebreak"
"newline" "newpage" "clearpage" "cleardoublepage"
"displaybreak" "allowdisplaybreaks"
"enlargethispage") t))
"enlargethispage")
t))
(general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
;;
;; Miscellany.
@ -649,7 +652,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
(defvar tex-verbatim-environments
'("verbatim" "verbatim*"))
(put 'tex-verbatim-environments 'safe-local-variable
(lambda (x) (null (delq t (mapcar 'stringp x)))))
(lambda (x) (null (delq t (mapcar #'stringp x)))))
(eval-when-compile
(defconst tex-syntax-propertize-rules
@ -1128,34 +1131,36 @@ subshell is initiated, `tex-shell-hook' is run."
(concat "[ \t]*\\(\\$\\$\\|"
"\\\\[][]\\|"
"\\\\" (regexp-opt (append
(mapcar 'car latex-section-alist)
(mapcar #'car latex-section-alist)
'("begin" "label" "end"
"item" "bibitem" "newline" "noindent"
"newpage" "footnote" "marginpar"
"parbox" "caption")) t)
"parbox" "caption"))
t)
"\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t)
"\\>\\)"))
(setq paragraph-separate
(concat "[\f%]\\|[ \t]*\\($\\|"
"\\\\[][]\\|"
"\\\\" (regexp-opt (append
(mapcar 'car latex-section-alist)
'("begin" "label" "end" )) t)
(mapcar #'car latex-section-alist)
'("begin" "label" "end" ))
t)
"\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
"noindent" "newpage" "footnote"
"marginpar" "parbox" "caption"))
"\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
"\\>\\)[ \t]*\\($\\|%\\)\\)"))
(setq-local imenu-create-index-function 'latex-imenu-create-index)
(setq-local imenu-create-index-function #'latex-imenu-create-index)
(setq-local tex-face-alist tex-latex-face-alist)
(add-hook 'fill-nobreak-predicate 'latex-fill-nobreak-predicate nil t)
(setq-local indent-line-function 'latex-indent)
(add-hook 'fill-nobreak-predicate #'latex-fill-nobreak-predicate nil t)
(setq-local indent-line-function #'latex-indent)
(setq-local fill-indent-according-to-mode t)
(add-hook 'completion-at-point-functions
'latex-complete-data nil 'local)
#'latex-complete-data nil 'local)
(setq-local outline-regexp latex-outline-regexp)
(setq-local outline-level 'latex-outline-level)
(setq-local forward-sexp-function 'latex-forward-sexp)
(setq-local outline-level #'latex-outline-level)
(setq-local forward-sexp-function #'latex-forward-sexp)
(setq-local skeleton-end-hook nil))
;;;###autoload
@ -1205,6 +1210,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
(defvar tildify-space-string)
(defvar tildify-foreach-region-function)
(declare-function tildify-foreach-ignore-environments
"tildify" (pairs callback _beg end))
(defvar tex--prettify-symbols-alist)
(defun tex-common-initialization ()
@ -1216,7 +1223,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
;; rather than using regex-based filtering.
(setq-local tildify-foreach-region-function
(apply-partially
'tildify-foreach-ignore-environments
#'tildify-foreach-ignore-environments
`(("\\\\\\\\" . "") ; do not remove this
(,(eval-when-compile
(concat "\\\\begin{\\("
@ -1534,8 +1541,7 @@ a skeleton (see `skeleton-insert').")
Puts point on a blank line between them."
(let ((choice (completing-read (format "LaTeX block name [%s]: "
latex-block-default)
(append latex-block-names
latex-standard-block-names)
(latex-complete-envnames)
nil nil nil nil latex-block-default)))
(setq latex-block-default choice)
(unless (or (member choice latex-standard-block-names)
@ -1592,17 +1598,32 @@ Puts point on a blank line between them."
(complete-with-action action keys key pred)))))
(defun latex-complete-envnames ()
(append latex-block-names latex-standard-block-names))
(completion-table-in-turn
(append latex-block-names latex-standard-block-names)
(completion-table-dynamic
(lambda (str)
(with-current-buffer (if (and (minibufferp) (minibuffer-selected-window))
(window-buffer (minibuffer-selected-window))
(current-buffer))
(save-excursion
(let ((comps '())
(pos (point)))
(goto-char (point-min))
(while (re-search-forward (concat "\\\\begin{\\(" str "[^}\n ]*\\)")
nil t)
(unless (and (<= (match-beginning 0) pos)
(>= (match-end 0) pos))
(push (match-string 1) comps)))
comps)))))))
(defun latex-complete-refkeys ()
(when (boundp 'reftex-docstruct-symbol)
(symbol-value reftex-docstruct-symbol)))
(defvar latex-complete-alist
;; TODO: Add \begin, \end, \ref, ...
'(("\\`\\\\\\(short\\)?cite\\'" . latex-complete-bibtex-keys)
("\\`\\\\\\(begin\\|end\\)\\'" . latex-complete-envnames)
("\\`\\\\[vf]?ref\\'" . latex-complete-refkeys)))
`(("\\`\\\\\\(short\\)?cite\\'" . ,#'latex-complete-bibtex-keys)
("\\`\\\\\\(begin\\|end\\)\\'" . ,#'latex-complete-envnames)
("\\`\\\\[vf]?ref\\'" . ,#'latex-complete-refkeys)))
(defun latex-complete-data ()
"Get completion-data at point."
@ -2185,7 +2206,7 @@ of the current buffer."
(defun tex-summarize-command (cmd)
(if (not (stringp cmd)) ""
(mapconcat 'identity
(mapconcat #'identity
(mapcar (lambda (s) (car (split-string s)))
(split-string cmd "\\s-*\\(?:;\\|&&\\)\\s-*"))
"&")))
@ -2367,7 +2388,8 @@ Only applies the FSPEC to the args part of FORMAT."
;; Substitute and return.
(if (and hist-cmd
(string-match (concat "[' \t\"]" (format-spec "%r" fspec)
"\\([;&' \t\"]\\|\\'\\)") hist-cmd))
"\\([;&' \t\"]\\|\\'\\)")
hist-cmd))
;; The history command was already applied to the same file,
;; so just reuse it.
hist-cmd
@ -2752,7 +2774,7 @@ Runs the shell command defined by `tex-show-queue-command'."
(defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>")
(defvar latex-noindent-environments '("document"))
(put 'latex-noindent-environments 'safe-local-variable
(lambda (x) (null (delq t (mapcar 'stringp x)))))
(lambda (x) (null (delq t (mapcar #'stringp x)))))
(defvar tex-latex-indent-syntax-table
(let ((st (make-syntax-table tex-mode-syntax-table)))