From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Sauermann Newsgroups: gmane.emacs.bugs Subject: bug#1012: Indentation of constant symbols Date: Wed, 01 Oct 2008 22:21:11 +0200 Message-ID: <48E3DBB7.9060709@sauermann-consulting.de> References: <48D9F761.1000805@gmx.at> <48D68650.1040907@sauermann-consulting.de> Reply-To: Markus Sauermann , 1012@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010308050807050500050004" X-Trace: ger.gmane.org 1222894231 12608 80.91.229.12 (1 Oct 2008 20:50:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 1 Oct 2008 20:50:31 +0000 (UTC) To: 1012@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 01 22:51:29 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 1Kl8f7-0000hB-U2 for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Oct 2008 22:51:10 +0200 Original-Received: from localhost ([127.0.0.1]:35686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl8e4-0002PN-Fb for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Oct 2008 16:50:04 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kl8dz-0002Nz-Jt for bug-gnu-emacs@gnu.org; Wed, 01 Oct 2008 16:49:59 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kl8dy-0002Nn-Q8 for bug-gnu-emacs@gnu.org; Wed, 01 Oct 2008 16:49:59 -0400 Original-Received: from [199.232.76.173] (port=54398 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl8dy-0002Nk-Kc for bug-gnu-emacs@gnu.org; Wed, 01 Oct 2008 16:49:58 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:42503) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kl8dx-0000Ap-WC for bug-gnu-emacs@gnu.org; Wed, 01 Oct 2008 16:49:58 -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 m91KntqP029653; Wed, 1 Oct 2008 13:49:56 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m91KU4Xg025032; Wed, 1 Oct 2008 13:30:04 -0700 X-Loop: don@donarmstrong.com Resent-From: Markus Sauermann Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 01 Oct 2008 20:30:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 1012 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 1012-submit@emacsbugs.donarmstrong.com id=B1012.122289248823707 (code B ref 1012); Wed, 01 Oct 2008 20:30:04 +0000 Original-Received: (at 1012) by emacsbugs.donarmstrong.com; 1 Oct 2008 20:21:28 +0000 Original-Received: from smtp1.bitpoint.de (smtp1.bitpoint.de [80.67.224.9]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m91KLMmU023701 for <1012@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 13:21:24 -0700 Original-Received: from p54994748.dip.t-dialin.net ([84.153.71.72]) by smtp1.bitpoint.de with esmtpa (Exim 4.67 (FreeBSD)) (envelope-from ) id 1Kl8CF-0007MQ-OV for 1012@emacsbugs.donarmstrong.com; Wed, 01 Oct 2008 22:21:20 +0200 User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) In-Reply-To: X-Enigmail-Version: 0.95.7 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Wed, 01 Oct 2008 16: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:20971 Archived-At: This is a multi-part message in MIME format. --------------010308050807050500050004 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Hello, my bug fix was not farsighted enough. Basically I fixed a part of the source code, which does nothing at all. I dug a bit deeper and noticed, that the following "source code 1" of the function calculate-lisp-indent in lisp-mode.el is a little bugged. --- BEGIN source code 1 --- ;; If the function has no special alignment ;; or it does not apply to this argument, ;; try to align a constant-symbol under the last ;; preceding constant symbol, if there is such one of ;; the last 2 preceding symbols, in the previous ;; uncommented line. (and (save-excursion (goto-char indent-point) (skip-chars-forward " \t") (looking-at ":")) ;; The last sexp may not be at the indentation ;; where it begins, so find that one, instead. (save-excursion (goto-char calculate-lisp-indent-last-sexp) ;; Handle prefix characters and whitespace ;; following an open paren. (Bug#1012) (backward-prefix-chars) (while (and (not (looking-back "^[ \t]*\\|([ \t]+")) (or (not containing-sexp) (< (1+ containing-sexp) (point)))) (forward-sexp -1) (backward-prefix-chars)) (setq calculate-lisp-indent-last-sexp (point))) (> calculate-lisp-indent-last-sexp (save-excursion (goto-char (1+ containing-sexp)) (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) (point))) (let ((parse-sexp-ignore-comments t) indent) (goto-char calculate-lisp-indent-last-sexp) (or (and (looking-at ":") (setq indent (current-column))) (and (< (save-excursion (beginning-of-line) (point)) (prog2 (backward-sexp) (point))) (looking-at ":") (setq indent (current-column)))) indent)) --- END source code 1 --- One part of that code implements the functionality as described in the comment at the beginning of the code. The other part tries to fix a problem, that is caused by this functionality, which is denoted in example 1, where :baz should be aligned under :foo and not under :foo2. --- BEGIN example 1 --- (:foo bar :foo2 bar2 :baz ar) --- END example 1 --- But this other part makes constant symbols to be indented in the same way as the usual indentation does. So discarding the whole code does not change any indentation except in some rare, mostly unused cases. See examples 2 for code snippets that are indented in the same way with or without this code. --- BEGIN examples 2 --- (:foo bar :baz) (foo bar :baz :foo2) (foo bar :baz bor :foo2) (:foo bar (:bar baz :asd)) --- END examples 2 --- These examples also contradict the description of the source code. I even think that the description of the code is not what the special handling of constant symbols should be like, as it causes the indentation described in example 1. So I suggest to treat constant symbols in the following way: If the sexp, preceding the constant symbol, begins in the same line as the containing sexp, then align it under the first appearance of a constant symbol between the beginning of the containing sexp and the the begin of the preceding sexp. If the sexp, preceding the constant symbol, does not begin in the same line as the containing sexp, then special treatment is not necessary, because it is handled by the usual indentation. Do not treat a constant symbol in a special way, if the containing sexp is a vector, since this would cause indentations in unwanted places. After applying "patch-1.txt", which implements this suggestions, the code in examples 2 is indented as shown in examples 3. --- BEGIN examples 3 --- (:foo bar :baz) (foo bar :baz :foo2) (foo bar :baz bor :foo2) (:foo bar (:bar baz :asd)) --- END examples 3 --- This implementation still has shortcomings in several unusual conditions, as examples 4 show, but I think this patch covers all common usages. --- BEGIN examples 4 --- (:foo cons :foo2 (bar baz :asd asd) :sad) (:foo (:bar baz :asd asd) :con con2 :sad) --- END examples 4 --- Regards, Markus Sauermann --------------010308050807050500050004 Content-Type: text/plain; name="patch-1.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-1.txt" Index: lisp-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v retrieving revision 1.228 diff -c -r1.228 lisp-mode.el *** lisp-mode.el 23 Sep 2008 17:59:28 -0000 1.228 --- lisp-mode.el 1 Oct 2008 19:10:51 -0000 *************** *** 1014,1055 **** (not retry) (funcall lisp-indent-function indent-point state)) ;; If the function has no special alignment ! ;; or it does not apply to this argument, ! ;; try to align a constant-symbol under the last ! ;; preceding constant symbol, if there is such one of ! ;; the last 2 preceding symbols, in the previous ! ;; uncommented line. (and (save-excursion (goto-char indent-point) (skip-chars-forward " \t") (looking-at ":")) ! ;; The last sexp may not be at the indentation ! ;; where it begins, so find that one, instead. ! (save-excursion ! (goto-char calculate-lisp-indent-last-sexp) ! ;; Handle prefix characters and whitespace ! ;; following an open paren. (Bug#1012) ! (backward-prefix-chars) ! (while (and (not (looking-back "^[ \t]*\\|([ \t]+")) ! (or (not containing-sexp) ! (< (1+ containing-sexp) (point)))) ! (forward-sexp -1) ! (backward-prefix-chars)) ! (setq calculate-lisp-indent-last-sexp (point))) ! (> calculate-lisp-indent-last-sexp ! (save-excursion ! (goto-char (1+ containing-sexp)) ! (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) ! (point))) (let ((parse-sexp-ignore-comments t) indent) ! (goto-char calculate-lisp-indent-last-sexp) ! (or (and (looking-at ":") ! (setq indent (current-column))) ! (and (< (save-excursion (beginning-of-line) (point)) ! (prog2 (backward-sexp) (point))) ! (looking-at ":") ! (setq indent (current-column)))) indent)) ;; another symbols or constants not preceded by a constant ;; as defined above. --- 1014,1046 ---- (not retry) (funcall lisp-indent-function indent-point state)) ;; If the function has no special alignment ! ;; or it does not apply to this argument, ! ;; try to treat a constant symbol in a special way. (and (save-excursion (goto-char indent-point) (skip-chars-forward " \t") (looking-at ":")) ! ;; Treat it only special, if the sexp preceding it begins ! ;; in the same line as the containing sexp ! (< calculate-lisp-indent-last-sexp ! (save-excursion (goto-char containing-sexp) ! (end-of-line) (point))) ! ;; Don't treat it special, if the containing sexp is a ! ;; vector ! (save-excursion (goto-char containing-sexp) ! (not (looking-at "\\["))) ! ;; Align it under the first constant symbol, if any, ! ;; between the beginning of the containing sexp and ! ;; the preceding sexp (let ((parse-sexp-ignore-comments t) indent) ! (goto-char (1+ containing-sexp)) ! (while (and (<= (point) calculate-lisp-indent-last-sexp) ! (not indent)) ! (skip-syntax-forward "-") ! (if (looking-at ":") ! (setq indent (current-column)) ! (forward-sexp))) indent)) ;; another symbols or constants not preceded by a constant ;; as defined above. --------------010308050807050500050004--