all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Sebastian Urban <mrsebastianurban@gmail.com>
Cc: 36358@debbugs.gnu.org
Subject: bug#36358: Indentation of not matched braces in latex-mode
Date: Mon, 24 Jun 2019 19:22:52 -0400	[thread overview]
Message-ID: <jwvpnn2sh7a.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <f987c496-c9f0-9645-1018-7a1f88431892@gmail.com> (Sebastian Urban's message of "Mon, 24 Jun 2019 18:08:45 +0200")

> If I use 'fill-paragraph' (M-q) on paragraph, inside things like
> \footnote{} or \emph{}, if they're long, text is indented with 2
> spaces - look below.

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

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


        Stefan


diff --git a/etc/NEWS b/etc/NEWS
index 74a8bbe8fa..0f764cd998 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -475,6 +475,9 @@ current and the previous or the next line, as before.
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
+** tex-mode
+*** 'latex-noindent-commands' stops indenting arguments of \emph and friends
+
 ** byte compiler
 *** byte-compile-dynamic is now obsolete
 This is because on the one hand it suffers from various misbehaviors in corner
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index 9c91d27b94..4511354a3d 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -2803,9 +2803,19 @@ tex-indent-arg
 (defvar tex-indent-basic 2)
 (defvar tex-indent-item tex-indent-basic)
 (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)))))
+(defcustom latex-noindent-environments '("document")
+  "Environments whose content is not indented by `tex-indent-basic'."
+  :type '(repeat string)
+  :safe (lambda (x) (lambda (x) (memq nil (mapcar #'stringp x))))
+  :group 'tex-file
+  :version "27.1")
+
+(defcustom latex-noindent-commands '("emph" "footnote")
+  "Commands for which `tex-indent-basic' should not be used."
+  :type '(repeat string)
+  :safe (lambda (x) (memq nil (mapcar #'stringp x)))
+  :group 'tex-file
+  :version "27.1")
 
 (defvar tex-latex-indent-syntax-table
   (let ((st (make-syntax-table tex-mode-syntax-table)))
@@ -2912,9 +2922,17 @@ latex-find-indent
 	       (current-column)
 	     ;; We're the first element after a hanging brace.
 	     (goto-char up-list-pos)
-	     (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)")
+	     (+ (if (if (eq (char-after) ?\{)
+                        (save-excursion
+                          (skip-chars-backward " \t")
+                          (let ((end (point)))
+                            (skip-chars-backward "a-zA-Z")
+                            (and (eq (char-before) ?\\)
+                                 (member (buffer-substring (point) end)
+                                         latex-noindent-commands))))
+                      (and (looking-at "\\\\begin *{\\([^\n}]+\\)")
 			 (member (match-string 1)
-				 latex-noindent-environments))
+				 latex-noindent-environments)))
 		    0 tex-indent-basic)
 		indent (latex-find-indent 'virtual))))
 	  ;; We're now at the "beginning" of a line.
diff --git a/test/manual/indent/latex-mode.tex b/test/manual/indent/latex-mode.tex
index 55c8e7033b..d314b98b48 100644
--- a/test/manual/indent/latex-mode.tex
+++ b/test/manual/indent/latex-mode.tex
@@ -8,4 +8,8 @@
 \url{/lib/modules/$(uname -r)},  %bug#11953.
 and install the appropriate \url{gspca-modules} package.
 
+Footnotes and emphasis shouldn't be indented \footnote{as can be seen here,
+for example}, \emph{or there
+as well}.
+
 \end{document}






  reply	other threads:[~2019-06-24 23:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24 16:08 bug#36358: Indentation of not matched braces in latex-mode Sebastian Urban
2019-06-24 23:22 ` Stefan Monnier [this message]
2019-06-25  7:30   ` Sebastian Urban
2019-06-25 14:53     ` Stefan Monnier
2019-06-26  7:46       ` Sebastian Urban
2019-06-26 13:49         ` Stefan Monnier
2019-06-27  8:53           ` Sebastian Urban
2019-06-29 20:08             ` Sebastian Urban
2019-06-29 21:02               ` Stefan Monnier
2020-07-09 17:18                 ` Sebastian Urban
2019-07-05 15:20               ` Basil L. Contovounesios

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvpnn2sh7a.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=36358@debbugs.gnu.org \
    --cc=mrsebastianurban@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.