lang/latex: rethink item continuation indentation
+ Rename +latex-indent-level-item-continuation to +latex-indent-item-continuation-offset, which more accurately reflects its purpose. + +latex-indent-item-continuation-offset now supports `align' and `auto' settings. + It can also be disabled by setting it to nil. Fixes #3877
This commit is contained in:
parent
1c6ea87832
commit
98826f33d0
2 changed files with 40 additions and 18 deletions
|
@ -1,43 +1,44 @@
|
||||||
;;; lang/latex/autoload.el -*- lexical-binding: t; -*-
|
;;; lang/latex/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +latex/LaTeX-indent-item ()
|
(defun +latex-indent-item-fn ()
|
||||||
"Provide proper indentation for LaTeX \"itemize\",\"enumerate\", and
|
"Indent LaTeX \"itemize\",\"enumerate\", and \"description\" environments.
|
||||||
\"description\" environments.
|
|
||||||
|
|
||||||
\"\\item\" is indented `LaTeX-indent-level' spaces relative to the the beginning
|
\"\\item\" is indented `LaTeX-indent-level' spaces relative to the the beginning
|
||||||
of the environment.
|
of the environment.
|
||||||
|
|
||||||
Continuation lines are indented either twice `LaTeX-indent-level', or
|
See `LaTeX-indent-level-item-continuation' for the indentation strategy this
|
||||||
`LaTeX-indent-level-item-continuation' if the latter is bound."
|
function uses."
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(let* ((offset LaTeX-indent-level)
|
(let* ((re-beg "\\\\begin{")
|
||||||
(contin (or (and (boundp '+latex-indent-level-item-continuation)
|
|
||||||
+latex-indent-level-item-continuation)
|
|
||||||
(* 4 offset)))
|
|
||||||
(re-beg "\\\\begin{")
|
|
||||||
(re-end "\\\\end{")
|
(re-end "\\\\end{")
|
||||||
(re-env "\\(itemize\\|\\enumerate\\|description\\)")
|
(re-env "\\(?:itemize\\|\\enumerate\\|description\\)")
|
||||||
(indent (save-excursion
|
(indent (save-excursion
|
||||||
(when (looking-at (concat re-beg re-env "}"))
|
(when (looking-at (concat re-beg re-env "}"))
|
||||||
(end-of-line))
|
(end-of-line))
|
||||||
(LaTeX-find-matching-begin)
|
(LaTeX-find-matching-begin)
|
||||||
(current-column))))
|
(current-column)))
|
||||||
|
(contin (pcase +latex-indent-item-continuation-offset
|
||||||
|
(`auto LaTeX-indent-level)
|
||||||
|
(`align 6)
|
||||||
|
(`nil (- LaTeX-indent-level))
|
||||||
|
(x x))))
|
||||||
(cond ((looking-at (concat re-beg re-env "}"))
|
(cond ((looking-at (concat re-beg re-env "}"))
|
||||||
(or (save-excursion
|
(or (save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(LaTeX-find-matching-begin)
|
(LaTeX-find-matching-begin)
|
||||||
(+ (current-column)
|
(+ (current-column)
|
||||||
|
LaTeX-indent-level
|
||||||
(if (looking-at (concat re-beg re-env "}"))
|
(if (looking-at (concat re-beg re-env "}"))
|
||||||
contin
|
contin
|
||||||
offset))))
|
0))))
|
||||||
indent))
|
indent))
|
||||||
((looking-at (concat re-end re-env "}"))
|
((looking-at (concat re-end re-env "}"))
|
||||||
indent)
|
indent)
|
||||||
((looking-at "\\\\item")
|
((looking-at "\\\\item")
|
||||||
(+ offset indent))
|
(+ LaTeX-indent-level indent))
|
||||||
((+ contin indent))))))
|
((+ contin LaTeX-indent-level indent))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +latex-fold-last-macro-a (&rest _)
|
(defun +latex-fold-last-macro-a (&rest _)
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
;;; lang/latex/config.el -*- lexical-binding: t; -*-
|
;;; lang/latex/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defvar +latex-indent-level-item-continuation 4
|
(defconst +latex-indent-item-continuation-offset 'align
|
||||||
"Custom indentation level for items in enumeration-type environments")
|
"Level to indent continuation of enumeration-type environments.
|
||||||
|
|
||||||
|
i.e. This affects \\item, \\enumerate, and \\description.
|
||||||
|
|
||||||
|
Set this to `align' for:
|
||||||
|
|
||||||
|
\\item lines aligned
|
||||||
|
like this.
|
||||||
|
|
||||||
|
Set to `auto' for continuation lines to be offset by `LaTeX-indent-line':
|
||||||
|
|
||||||
|
\\item lines aligned
|
||||||
|
like this, assuming LaTeX-indent-line == 2
|
||||||
|
|
||||||
|
Any other fixed integer will be added to `LaTeX-item-indent' and the current
|
||||||
|
indentation level.
|
||||||
|
|
||||||
|
Set this to `nil' to disable all this behavior.
|
||||||
|
|
||||||
|
You'll need to adjust `LaTeX-item-indent' to control indentation of \\item
|
||||||
|
itself.")
|
||||||
|
|
||||||
(defvar +latex-enable-unicode-math nil
|
(defvar +latex-enable-unicode-math nil
|
||||||
"If non-nil, use `company-math-symbols-unicode' backend in LaTeX-mode,
|
"If non-nil, use `company-math-symbols-unicode' backend in LaTeX-mode,
|
||||||
|
@ -130,8 +150,9 @@ Math faces should stay fixed by the mixed-pitch blacklist, this is mostly for
|
||||||
;; Provide proper indentation for LaTeX "itemize","enumerate", and
|
;; Provide proper indentation for LaTeX "itemize","enumerate", and
|
||||||
;; "description" environments. See
|
;; "description" environments. See
|
||||||
;; http://emacs.stackexchange.com/questions/3083/how-to-indent-items-in-latex-auctex-itemize-environments
|
;; http://emacs.stackexchange.com/questions/3083/how-to-indent-items-in-latex-auctex-itemize-environments
|
||||||
|
;; Set `+latex-indent-item-continuation-offset' to 0 to disable this
|
||||||
(dolist (env '("itemize" "enumerate" "description"))
|
(dolist (env '("itemize" "enumerate" "description"))
|
||||||
(add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item)))
|
(add-to-list 'LaTeX-indent-environment-list `(,env +latex-indent-item-fn)))
|
||||||
|
|
||||||
;; Fix #1849: allow fill-paragraph in itemize/enumerate
|
;; Fix #1849: allow fill-paragraph in itemize/enumerate
|
||||||
(defadvice! +latex--re-indent-itemize-and-enumerate-a (orig-fn &rest args)
|
(defadvice! +latex--re-indent-itemize-and-enumerate-a (orig-fn &rest args)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue