From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.devel Subject: Re: Proposal: make up-list escape strings Date: Wed, 09 Apr 2014 08:17:04 +0200 Message-ID: <5344E5E0.8080709@online.de> References: <534482F2.6010504@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1397023963 22183 80.91.229.3 (9 Apr 2014 06:12:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Apr 2014 06:12:43 +0000 (UTC) Cc: Daniel Colascione , Stefan Monnier To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 09 08:12:36 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WXlkN-0007oS-DB for ged-emacs-devel@m.gmane.org; Wed, 09 Apr 2014 08:12:31 +0200 Original-Received: from localhost ([::1]:44504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlkM-0003hM-IY for ged-emacs-devel@m.gmane.org; Wed, 09 Apr 2014 02:12:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlkC-0003hC-G3 for emacs-devel@gnu.org; Wed, 09 Apr 2014 02:12:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXlk4-00061R-UO for emacs-devel@gnu.org; Wed, 09 Apr 2014 02:12:20 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.131]:52070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXlk4-00061F-Kc for emacs-devel@gnu.org; Wed, 09 Apr 2014 02:12:12 -0400 Original-Received: from purzel.sitgens (brln-4d0c5b3a.pool.mediaWays.net [77.12.91.58]) by mrelayeu.kundenserver.de (node=mreue001) with ESMTP (Nemesis) id 0M9B9x-1Whuk80zTp-00CRRg; Wed, 09 Apr 2014 08:12:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <534482F2.6010504@dancol.org> X-Provags-ID: V02:K0:90WaOOwV4OHbyVQxPtX80eBzwAVjJNnUx9iBbkTtyFh 3llu4+L27w9Zbrt0bMDNR97NQhA0/ObH3w5E+vOIGEyL9/iYXs nxXleT4Ue5HqmWmb4asEwbkSpDV8FAa81nnPA/GJsmAHjT8oAc HUHrF5/3QfLuIcSinDUH9007jXMDQv0f1vSHHvYC2t7EpmPDEk 7KxfZbOw6bd8QY5jo7SUz2+SrimGGQmDlHkf/CfynQTJSgi7F4 9zX6yhmzSRtFCdd6ZfumsNEbCRX2rPiUq0LlXoukYdGP3rWjCv 5ztqDlasTuBXmo4+Q1Yas/I1wuymSfwIWsuJ2Gxv/bSHH13IaQ kdqqKUg5nPgh52vcwPF0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 212.227.126.131 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:171360 Archived-At: Am 09.04.2014 01:14, schrieb Daniel Colascione: > Here's a small patch that makes backward-up-list and up-list escape > strings as well as explicit lists. This behavior is active only when > these functions are called interactively or when lisp explicitly asks > for this behavior, so the change shouldn't pose a compatibility risk. > Backing out of strings is generally a useful thing to do when you want > to operate on the string as a whole. > > === modified file 'lisp/emacs-lisp/lisp.el' > --- lisp/emacs-lisp/lisp.el 2014-02-26 02:31:27 +0000 > +++ lisp/emacs-lisp/lisp.el 2014-04-08 23:12:16 +0000 > @@ -140,38 +140,58 @@ > (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) > (setq arg (- arg inc))))) > > -(defun backward-up-list (&optional arg) > +(defun backward-up-list (&optional arg escape-strings) > "Move backward out of one level of parentheses. > This command will also work on other parentheses-like expressions > defined by the current language mode. > With ARG, do this that many times. > A negative argument means move forward but still to a less deep spot. > -This command assumes point is not in a string or comment." > - (interactive "^p") > - (up-list (- (or arg 1)))) > +This command assumes point is not in a string or comment. > +If ESCAPE-STRINGS is non-nil (as it is interactively), treat > +encoding strings as sexps." > + (interactive "^p\nd") > + (up-list (- (or arg 1)) escape-strings)) > > -(defun up-list (&optional arg) > +(defun up-list (&optional arg escape-strings) > "Move forward out of one level of parentheses. > This command will also work on other parentheses-like expressions > defined by the current language mode. > With ARG, do this that many times. > A negative argument means move backward but still to a less deep spot. > -This command assumes point is not in a string or comment." > - (interactive "^p") > +If ESCAPE-STRINGS is non-nil (as it is interactively), treat > +encoding strings as sexps." > + (interactive "^p\nd") > (or arg (setq arg 1)) > (let ((inc (if (> arg 0) 1 -1)) > pos) > (while (/= arg 0) > (if (null forward-sexp-function) > - (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) > + (condition-case err > + (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) > + (scan-error > + (or (and escape-strings > + (let ((syntax (syntax-ppss))) > + (and (nth 3 syntax) > + (nth 8 syntax)) > + (goto-char (nth 8 syntax)) > + (when (> arg 0) (forward-sexp)) > + t)) > + (signal (car err) (cdr err))))) > (condition-case err > (while (progn (setq pos (point)) > (forward-sexp inc) > (/= (point) pos))) > (scan-error (goto-char (nth (if (> arg 0) 3 2) err)))) > (if (= (point) pos) > - (signal 'scan-error > - (list "Unbalanced parentheses" (point) (point))))) > + (or (and escape-strings > + (let ((syntax (syntax-ppss))) > + (and (nth 3 syntax) > + (nth 8 syntax)) > + (goto-char (nth 8 syntax)) > + (when (> arg 0) (forward-sexp)) > + t)) > + (signal 'scan-error > + (list "Unbalanced parentheses" (point) (point)))))) > (setq arg (- arg inc))))) > > (defun kill-sexp (&optional arg) > > Probably the most ancient bug :-) IMO you don't need "and" going out of comments/strings just (goto-char (nth 8 syntax)) Here is the form I'm using for ages: (defun ar-up-list (arg) "Move forward out of one level of parentheses. With ARG, do this that many times. A negative argument means move backward but still to a less deep spot." (interactive "p") (let ((orig (point)) (pps (syntax-ppss)) erg) (and (nth 8 pps) (goto-char (nth 8 pps))) (ignore-errors (up-list arg)) (and (< orig (point)) (setq erg (point))) (when (interactive-p) (message "%s" erg)) erg)) Cheers, Andreas