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; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +latex/LaTeX-indent-item ()
|
||||
"Provide proper indentation for LaTeX \"itemize\",\"enumerate\", and
|
||||
\"description\" environments.
|
||||
(defun +latex-indent-item-fn ()
|
||||
"Indent LaTeX \"itemize\",\"enumerate\", and \"description\" environments.
|
||||
|
||||
\"\\item\" is indented `LaTeX-indent-level' spaces relative to the the beginning
|
||||
of the environment.
|
||||
|
||||
Continuation lines are indented either twice `LaTeX-indent-level', or
|
||||
`LaTeX-indent-level-item-continuation' if the latter is bound."
|
||||
See `LaTeX-indent-level-item-continuation' for the indentation strategy this
|
||||
function uses."
|
||||
(save-match-data
|
||||
(let* ((offset LaTeX-indent-level)
|
||||
(contin (or (and (boundp '+latex-indent-level-item-continuation)
|
||||
+latex-indent-level-item-continuation)
|
||||
(* 4 offset)))
|
||||
(re-beg "\\\\begin{")
|
||||
(let* ((re-beg "\\\\begin{")
|
||||
(re-end "\\\\end{")
|
||||
(re-env "\\(itemize\\|\\enumerate\\|description\\)")
|
||||
(re-env "\\(?:itemize\\|\\enumerate\\|description\\)")
|
||||
(indent (save-excursion
|
||||
(when (looking-at (concat re-beg re-env "}"))
|
||||
(end-of-line))
|
||||
(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 "}"))
|
||||
(or (save-excursion
|
||||
(beginning-of-line)
|
||||
(ignore-errors
|
||||
(LaTeX-find-matching-begin)
|
||||
(+ (current-column)
|
||||
LaTeX-indent-level
|
||||
(if (looking-at (concat re-beg re-env "}"))
|
||||
contin
|
||||
offset))))
|
||||
0))))
|
||||
indent))
|
||||
((looking-at (concat re-end re-env "}"))
|
||||
indent)
|
||||
((looking-at "\\\\item")
|
||||
(+ offset indent))
|
||||
((+ contin indent))))))
|
||||
(+ LaTeX-indent-level indent))
|
||||
((+ contin LaTeX-indent-level indent))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +latex-fold-last-macro-a (&rest _)
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
;;; lang/latex/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +latex-indent-level-item-continuation 4
|
||||
"Custom indentation level for items in enumeration-type environments")
|
||||
(defconst +latex-indent-item-continuation-offset 'align
|
||||
"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
|
||||
"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
|
||||
;; "description" environments. See
|
||||
;; 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"))
|
||||
(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
|
||||
(defadvice! +latex--re-indent-itemize-and-enumerate-a (orig-fn &rest args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue