bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36358: Indentation of not matched braces in latex-mode


From: Sebastian Urban
Subject: bug#36358: Indentation of not matched braces in latex-mode
Date: Tue, 25 Jun 2019 09:30:35 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Thunderbird/60.7.2

I just pushed the patch below which lets you specify commands whose
args shouldn't be indented this way.

Hmmm... or I don't understand how "specify commands whose args
shouldn't be indented" will work in practice, or this may be wrong
path.  It's not about \emph{} or \footnote{}, it's about every command
which use '{}' (braces), so in latex... most of them(?).  Therefore if
you let people add them to the list it'll grow really big - just look
at font styles: \textrm{}, \textit{}, \textmd{}, \textbf{}, \textup{},
\textsl{}, \textsf{}, \textsc{}, \texttt{}, \textnormal{} - we could
probably use "\text*", but there are other commands, for example the
ones we define as new in preamble.

Unless this patch is temporary lifebuoy for those who don't want to
set 'tex-indent-basic' to 0, then well... carry on. :)

Note that the patch is for Emacs's bundled tex-mode, whereas you
seem to be using AUCTeX, which uses its own indentation code.

No, I'm _not_ using AUCTeX, I'm using latex-mode.  I only pointed to
AUCTeX, because when I was looking for answer to this problem, I found
solution (helpful internet) in AUCTeX - 'TeX-brace-indent-level'
variable - and wanted something similar in latex-mode.

Also I found code in theirs (AUCTeX) TEX.EL, which may help a bit.
It may, but since I basically know no Elisp, I may be wrong.

(defcustom TeX-brace-indent-level 2
  "*The level of indentation produced by an open brace."
  :group 'TeX-indentation
  :type 'integer)

(defun TeX-brace-count-line ()
  "Count number of open/closed braces."
  (save-excursion
    (let ((count 0) (limit (line-end-position)) char)
      (while (progn
               (skip-chars-forward "^{}\\\\" limit)
               (when (and (< (point) limit) (not (TeX-in-comment)))
                 (setq char (char-after))
                 (forward-char)
                 (cond ((eq char ?\{)
                        (setq count (+ count TeX-brace-indent-level)))
                       ((eq char ?\})
                        (setq count (- count TeX-brace-indent-level)))
                       ((eq char ?\\)
                        (when (< (point) limit)
                          (forward-char)
                          t))))))
      count)))

This variable is also used in theirs LATEX.EL - L3366, L3503.  Both
functions too big to paste, I think.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]