From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: bug#954: indentation in latex-mode in emacs-23 Date: Wed, 24 Sep 2008 10:18:19 +0200 Message-ID: <48D9F7CB.2010900@gmx.at> References: <48D88DB3.1090205@gmx.at> <221cda020809230413t42e532c0m24fbf8e700c6c582@mail.gmail.com> <48D8E0E7.1090307@gmx.at> <221cda020809230545o111a51ffje05f4e2fae972876@mail.gmail.com> Reply-To: martin rudalics , 954@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020701080501060803000000" X-Trace: ger.gmane.org 1222246270 2201 80.91.229.12 (24 Sep 2008 08:51:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Sep 2008 08:51:10 +0000 (UTC) Cc: 954@emacsbugs.donarmstrong.com To: Chirok Han Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 24 10:52:03 2008 connect(): Connection refused Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KiQ5V-0002zJ-E6 for geb-bug-gnu-emacs@m.gmane.org; Wed, 24 Sep 2008 10:51:10 +0200 Original-Received: from localhost ([127.0.0.1]:50685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KiQ4T-0003Gk-8c for geb-bug-gnu-emacs@m.gmane.org; Wed, 24 Sep 2008 04:50:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KiQ4O-0003GX-CR for bug-gnu-emacs@gnu.org; Wed, 24 Sep 2008 04:50:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KiQ4N-0003G2-FQ for bug-gnu-emacs@gnu.org; Wed, 24 Sep 2008 04:49:59 -0400 Original-Received: from [199.232.76.173] (port=56468 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KiQ4N-0003Fz-C2 for bug-gnu-emacs@gnu.org; Wed, 24 Sep 2008 04:49:59 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:47676) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KiQ4M-0000CH-Pu for bug-gnu-emacs@gnu.org; Wed, 24 Sep 2008 04:49:59 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8O8nr8w013878; Wed, 24 Sep 2008 01:49:54 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m8O8U2lP009247; Wed, 24 Sep 2008 01:30:02 -0700 X-Loop: don@donarmstrong.com Resent-From: martin rudalics Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 24 Sep 2008 08:30:02 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 954 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 954-submit@emacsbugs.donarmstrong.com id=B954.12222446027995 (code B ref 954); Wed, 24 Sep 2008 08:30:02 +0000 Original-Received: (at 954) by emacsbugs.donarmstrong.com; 24 Sep 2008 08:23:22 +0000 Original-Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with SMTP id m8O8NG9G007983 for <954@emacsbugs.donarmstrong.com>; Wed, 24 Sep 2008 01:23:17 -0700 Original-Received: (qmail invoked by alias); 24 Sep 2008 08:23:10 -0000 Original-Received: from 62-47-41-49.adsl.highway.telekom.at (EHLO [62.47.41.49]) [62.47.41.49] by mail.gmx.net (mp025) with SMTP; 24 Sep 2008 10:23:10 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18leL5LJfAlyKDmrksqchaHM7+VVTMu7LyU0TNJyv bxW7VesdNBHoQp User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: <221cda020809230545o111a51ffje05f4e2fae972876@mail.gmail.com> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.8,0.49 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Wed, 24 Sep 2008 04:49:59 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:20722 Archived-At: This is a multi-part message in MIME format. --------------020701080501060803000000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > It's not something I can convince you about. And I don't think there > is any correct or incorrect formatting style. It's just from my 10 > years experience. As I get older, it gets harder to accommodate new > things no matter how small they are.... ... sounds convincing. What about the attached patch? martin --------------020701080501060803000000 Content-Type: text/plain; name="954.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="954.diff" *** textmodes/tex-mode.el.~1.218.~ 2008-09-23 10:17:14.531250000 +0200 --- textmodes/tex-mode.el 2008-09-24 09:57:17.203125000 +0200 *************** *** 1482,1487 **** --- 1482,1489 ---- (push-mark) (goto-char spot))) + (defvar latex-handle-escaped-parens t) + ;; Don't think this one actually _needs_ (for the purposes of ;; tex-mode) to handle escaped parens. (defun latex-backward-sexp-1 () *************** *** 1489,1499 **** (let ((pos (point)) (forward-sexp-function)) (backward-sexp 1) ! (cond ((looking-at "\\\\\\(begin\\>\\|[[({]\\)") (signal 'scan-error (list "Containing expression ends prematurely" (point) (prog1 (point) (goto-char pos))))) ! ((looking-at "\\\\\\([])}]\\)") (tex-last-unended-eparen (match-string 1))) ((eq (char-after) ?{) (let ((newpos (point))) --- 1491,1505 ---- (let ((pos (point)) (forward-sexp-function)) (backward-sexp 1) ! (cond ((looking-at ! (if latex-handle-escaped-parens ! "\\\\\\(begin\\>\\|[[({]\\)" ! "\\\\begin\\>")) (signal 'scan-error (list "Containing expression ends prematurely" (point) (prog1 (point) (goto-char pos))))) ! ((and latex-handle-escaped-parens ! (looking-at "\\\\\\([])}]\\)")) (tex-last-unended-eparen (match-string 1))) ((eq (char-after) ?{) (let ((newpos (point))) *************** *** 1528,1539 **** (tex-next-unmatched-end)) ;; A better way to handle this, \( .. \) etc, is probably to ;; temporarily change the syntax of the \ in \( to punctuation. ! ((looking-back "\\\\[])}]") (signal 'scan-error (list "Containing expression ends prematurely" (- (point) 2) (prog1 (point) (goto-char pos))))) ! ((looking-back "\\\\\\([({[]\\)") (tex-next-unmatched-eparen (match-string 1))) (t (goto-char newpos)))))) --- 1534,1547 ---- (tex-next-unmatched-end)) ;; A better way to handle this, \( .. \) etc, is probably to ;; temporarily change the syntax of the \ in \( to punctuation. ! ((and latex-handle-escaped-parens ! (looking-back "\\\\[])}]")) (signal 'scan-error (list "Containing expression ends prematurely" (- (point) 2) (prog1 (point) (goto-char pos))))) ! ((and latex-handle-escaped-parens ! (looking-back "\\\\\\([({[]\\)")) (tex-next-unmatched-eparen (match-string 1))) (t (goto-char newpos)))))) *************** *** 2568,2670 **** (indent-line-to indent) (save-excursion (indent-line-to indent))))))) (defun latex-find-indent (&optional virtual) "Find the proper indentation of text after point. VIRTUAL if non-nil indicates that we're only trying to find the indentation in order to determine the indentation of something else. There might be text before point." ! (save-excursion ! (skip-chars-forward " \t") ! (or ! ;; Stick the first line at column 0. ! (and (= (point-min) (line-beginning-position)) 0) ! ;; Trust the current indentation, if such info is applicable. ! (and virtual (save-excursion (skip-chars-backward " \t&") (bolp)) ! (current-column)) ! ;; Stick verbatim environments to the left margin. ! (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)") ! (member (match-string 2) tex-verbatim-environments) ! 0) ! ;; Put leading close-paren where the matching open paren would be. ! (let (escaped) ! (and (or (eq (latex-syntax-after) ?\)) ! ;; Try to handle escaped close parens but keep original ! ;; position if it doesn't work out. ! (setq escaped (looking-at "\\\\\\([])}]\\)"))) ! (ignore-errors ! (save-excursion ! (when escaped ! (goto-char (match-beginning 1))) ! (latex-skip-close-parens) (latex-backward-sexp-1) ! (latex-find-indent 'virtual))))) ! ;; Default (maybe an argument) ! (let ((pos (point)) ! ;; Outdent \item if necessary. ! (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0)) ! up-list-pos) ! ;; Find the previous point which determines our current indentation. ! (condition-case err ! (progn ! (latex-backward-sexp-1) ! (while (> (current-column) (current-indentation)) ! (latex-backward-sexp-1))) ! (scan-error ! (setq up-list-pos (nth 2 err)))) ! (cond ! ((= (point-min) pos) 0) ; We're really just indenting the first line. ! ((integerp up-list-pos) ! ;; Have to indent relative to the open-paren. ! (goto-char up-list-pos) ! (if (and (not tex-indent-allhanging) ! (save-excursion ! ;; Make sure we're an argument to a macro and ! ;; that the macro is at the beginning of a line. ! (condition-case nil ! (progn ! (while (eq (char-syntax (char-after)) ?\() ! (forward-sexp -1)) ! (and (eq (char-syntax (char-after)) ?/) ! (progn (skip-chars-backward " \t&") ! (bolp)))) ! (scan-error nil))) ! (> pos (progn (latex-down-list) ! (forward-comment (point-max)) ! (point)))) ! ;; Align with the first element after the open-paren. ! (current-column) ! ;; We're the first element after a hanging brace. (goto-char up-list-pos) ! (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)") ! (member (match-string 1) ! latex-noindent-environments)) ! 0 tex-indent-basic) ! indent (latex-find-indent 'virtual)))) ! ;; We're now at the "beginning" of a line. ! ((not (and (not virtual) (eq (char-after) ?\\))) ! ;; Nothing particular here: just keep the same indentation. ! (+ indent (current-column))) ! ;; We're now looking at a macro call. ! ((looking-at tex-indent-item-re) ! ;; Indenting relative to an item, have to re-add the outdenting. ! (+ indent (current-column) tex-indent-item)) ! (t ! (let ((col (current-column))) ! (if (or (not (eq (char-syntax (or (char-after pos) ?\s)) ?\()) ! ;; Can't be an arg if there's an empty line inbetween. ! (save-excursion (re-search-forward "^[ \t]*$" pos t))) ! ;; If the first char was not an open-paren, there's ! ;; a risk that this is really not an argument to the ! ;; macro at all. ! (+ indent col) ! (forward-sexp 1) ! (if (< (line-end-position) ! (save-excursion (forward-comment (point-max)) ! (point))) ! ;; we're indenting the first argument. ! (min (current-column) (+ tex-indent-arg col)) ! (skip-syntax-forward " ") ! (current-column)))))))))) ;;; DocTeX support (defun doctex-font-lock-^^A () --- 2576,2690 ---- (indent-line-to indent) (save-excursion (indent-line-to indent))))))) + (defcustom latex-indent-within-escaped-parens nil + "Non-nil means add extra indent to text within escaped parens. + When this is non-nil, text within matching pairs of escaped + parens is indented at the column following the open paren. The + default value does not add any extra indent thus providing the + behavior of Emacs 22 and earlier." + :type 'boolean + :group 'tex + :version "23.1") + (defun latex-find-indent (&optional virtual) "Find the proper indentation of text after point. VIRTUAL if non-nil indicates that we're only trying to find the indentation in order to determine the indentation of something else. There might be text before point." ! (let ((latex-handle-escaped-parens latex-indent-within-escaped-parens)) ! (save-excursion ! (skip-chars-forward " \t") ! (or ! ;; Stick the first line at column 0. ! (and (= (point-min) (line-beginning-position)) 0) ! ;; Trust the current indentation, if such info is applicable. ! (and virtual (save-excursion (skip-chars-backward " \t&") (bolp)) ! (current-column)) ! ;; Stick verbatim environments to the left margin. ! (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)") ! (member (match-string 2) tex-verbatim-environments) ! 0) ! ;; Put leading close-paren where the matching open paren would be. ! (let (escaped) ! (and (or (eq (latex-syntax-after) ?\)) ! ;; Try to handle escaped close parens but keep ! ;; original position if it doesn't work out. ! (and latex-handle-escaped-parens ! (setq escaped (looking-at "\\\\\\([])}]\\)")))) ! (ignore-errors ! (save-excursion ! (when escaped ! (goto-char (match-beginning 1))) ! (latex-skip-close-parens) ! (latex-backward-sexp-1) ! (latex-find-indent 'virtual))))) ! ;; Default (maybe an argument) ! (let ((pos (point)) ! ;; Outdent \item if necessary. ! (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0)) ! up-list-pos) ! ;; Find the previous point which determines our current indentation. ! (condition-case err ! (progn (latex-backward-sexp-1) ! (while (> (current-column) (current-indentation)) ! (latex-backward-sexp-1))) ! (scan-error ! (setq up-list-pos (nth 2 err)))) ! (cond ! ((= (point-min) pos) 0) ; We're really just indenting the first line. ! ((integerp up-list-pos) ! ;; Have to indent relative to the open-paren. (goto-char up-list-pos) ! (if (and (not tex-indent-allhanging) ! (save-excursion ! ;; Make sure we're an argument to a macro and ! ;; that the macro is at the beginning of a line. ! (condition-case nil ! (progn ! (while (eq (char-syntax (char-after)) ?\() ! (forward-sexp -1)) ! (and (eq (char-syntax (char-after)) ?/) ! (progn (skip-chars-backward " \t&") ! (bolp)))) ! (scan-error nil))) ! (> pos (progn (latex-down-list) ! (forward-comment (point-max)) ! (point)))) ! ;; Align with the first element after the open-paren. ! (current-column) ! ;; We're the first element after a hanging brace. ! (goto-char up-list-pos) ! (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)") ! (member (match-string 1) ! latex-noindent-environments)) ! 0 tex-indent-basic) ! indent (latex-find-indent 'virtual)))) ! ;; We're now at the "beginning" of a line. ! ((not (and (not virtual) (eq (char-after) ?\\))) ! ;; Nothing particular here: just keep the same indentation. ! (+ indent (current-column))) ! ;; We're now looking at a macro call. ! ((looking-at tex-indent-item-re) ! ;; Indenting relative to an item, have to re-add the outdenting. ! (+ indent (current-column) tex-indent-item)) ! (t ! (let ((col (current-column))) ! (if (or (not (eq (char-syntax (or (char-after pos) ?\s)) ?\()) ! ;; Can't be an arg if there's an empty line inbetween. ! (save-excursion (re-search-forward "^[ \t]*$" pos t))) ! ;; If the first char was not an open-paren, there's ! ;; a risk that this is really not an argument to the ! ;; macro at all. ! (+ indent col) ! (forward-sexp 1) ! (if (< (line-end-position) ! (save-excursion (forward-comment (point-max)) ! (point))) ! ;; we're indenting the first argument. ! (min (current-column) (+ tex-indent-arg col)) ! (skip-syntax-forward " ") ! (current-column))))))))))) ;;; DocTeX support (defun doctex-font-lock-^^A () --------------020701080501060803000000--