From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Common Lisp indentation bug fix/new feature Date: Mon, 21 Nov 2011 23:26:56 +0100 Organization: Programmerer Ingebrigtsen Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1321914451 20079 80.91.229.12 (21 Nov 2011 22:27:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2011 22:27:31 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 21 23:27:27 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RScKj-000225-7F for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2011 23:27:25 +0100 Original-Received: from localhost ([::1]:36389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RScKi-0006X5-Ot for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2011 17:27:24 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:38732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RScKc-0006Sv-Bv for emacs-devel@gnu.org; Mon, 21 Nov 2011 17:27:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RScKY-0008DW-C5 for emacs-devel@gnu.org; Mon, 21 Nov 2011 17:27:18 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:45848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RScKY-0008Cs-0A for emacs-devel@gnu.org; Mon, 21 Nov 2011 17:27:14 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RScKT-0001ta-Ti for emacs-devel@gnu.org; Mon, 21 Nov 2011 23:27:09 +0100 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Nov 2011 23:27:09 +0100 Original-Received: from larsi by cm-84.215.51.58.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Nov 2011 23:27:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 91 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.215.51.58.getinternet.no Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAHlBMVEVCMzNvXVuKdnLKv7Tz 8Nz+/upVRUSnl5ExJSQaERD2ze/VAAACY0lEQVQ4jW3TQW+bMBQAYLeakHuLnYmoR9wpbo+NXfED TNQfAFGvwCY3vY2Qje5GeojgluyQ4X+7Z2CQVnvilE/PL35+D63aEOJBKKGWqz78O9TDw49cPanV AK89LJWSQRgMoO47UKKPf2epRZ8BRaSQyzFjgEAEQfBwflQwHnwWjxmqSuRorRNigzHGiyLvoCod jRDSbYB7ZNoDchwUQxZztW7zAPwWkANfkou5BcrYzTno7WNG2owRSqiAboQquGtr0HeQ+rnKfW+E nwBWpr5UcsE+QIUvtoHwl0+bj1BdSqU+Ql0DPBe2s0/M/q8BjDEHsimgiSHTZwC/m9M85VIsw5ln m3IGxzimW7GMpswCtfC9hbeq3OVCRlNu28VG2MPHcxk9UwveCBggBUhp28cRrvbxm+YyTDzXFhmh LtFxkoowyYgDMB3AILzTiQg0I3EPry3Ak9Q7yuXcm8VQ5PMA66aqHcrzW8LhjZMBDhPT1MdZNrve e/CW41HHW9NUfzglLydcobOM33emQYfZLFtXdmb0CNfmoOvTBc8m7ZRZ+GVhd2UajatTutkwF6p/ 62GygzeBSawmN2JDxUR/7eDkxZBVErI205zkKnN6OBbY3j2hbn3hh4VUbg+7pDaN2RE2X+9zJUO1 6OHSw6auTy5z8Z6KQGzIAC5C5UETN+EsZx71PnVgHwFVpkwoLxiDoRf9PRIYJoRNA1MAQ8JhwL50 YBcphjINjLCTFiM4cFeE68auG+EWth2UGGmMK9NAFVjNvIM7uJhdO7ddzHZnLUTFC4oi2P73Ea3C e4Nk8J9Y4PovVwFgA0kq8J8AAAAASUVORK5CYII= Mail-Copies-To: never X-Now-Playing: Various's _FabricLIVE 59_: "Crazy Bald Heads - First Born" User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.91 (gnu/linux) Cancel-Lock: sha1:2wZrrpqmoQIbhmPlNZ68vCoQUsQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:146121 Archived-At: This is how much (most? some? I haven't actually counted) Common Lisp code found out in the world looks like: (defun foo () (loop for z from 1 upto 5 do (princ z) (terpri) (terpri))) That is, the statements after DO/DOING/FINALLY/etc line up so that you can see that they are part of the same block of code. Unfortunately, the CL indentation code does this instead: (loop for z from 1 upto 5 do (princ z) (terpri) (terpri) Now, one can adjust the indentation with `lisp-loop-forms-indentation', so I could just increase it by 1 and things would be OK? Nope, since then FINALLY would look like: (loop for z from 1 upto 5 finally (princ z) (terpri) (terpri) With the following patch (and a defcustom adjustment), we would allow getting the desired behaviour. The defaults don't change, though, so this wouldn't be a user-visible change, unless the set `lisp-loop-forms-indentation' to nil. So would it be OK to apply this, or is it too new-featurish? I kinda think it fixes an indentation bug... === modified file 'lisp/emacs-lisp/cl-indent.el' --- lisp/emacs-lisp/cl-indent.el 2011-11-21 21:58:38 +0000 +++ lisp/emacs-lisp/cl-indent.el 2011-11-21 22:15:28 +0000 @@ -152,11 +152,26 @@ (error t))) +(defun common-lisp-loop-keyword-length (loop-start) + "Return the length of the preceding loop keyword. +Stop looking before LOOP-START." + (save-excursion + (let ((length 0)) + (while (and (zerop length) + (> (point) loop-start)) + (beginning-of-line) + (when (looking-at "^\\s-*\\(loop\\s-*\\)?\\(:?\\sw+\\|;\\)") + (setq length (length (match-string 2)))) + (forward-line -1)) + length))) + + (defun common-lisp-loop-part-indentation (indent-point state) "Compute the indentation of loop form constituents." - (let* ((loop-indentation (save-excursion - (goto-char (elt state 1)) - (current-column)))) + (let ((loop-indentation (save-excursion + (goto-char (elt state 1)) + (current-column))) + (case-fold-search t)) (goto-char indent-point) (beginning-of-line) (list @@ -165,7 +180,13 @@ ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)") (+ loop-indentation lisp-loop-keyword-indentation)) (t - (+ loop-indentation lisp-loop-forms-indentation))) + (+ loop-indentation + lisp-loop-keyword-indentation + (or lisp-loop-forms-indentation + (1+ (common-lisp-loop-keyword-length + (or (save-excursion + (re-search-backward "(\\s-*loop" nil t)) + indent-point))))))) ;; Tell the caller that the next line needs recomputation, even ;; though it doesn't start a sexp. loop-indentation))) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog http://lars.ingebrigtsen.no/