From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] fix goto-line Date: Fri, 29 Jul 2011 14:15:33 +0300 Organization: JURTA Message-ID: <8762ml5odm.fsf@mail.jurta.org> References: <874o26muk2.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1311938425 4286 80.91.229.12 (29 Jul 2011 11:20:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 29 Jul 2011 11:20:25 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 29 13:20:21 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 1Qml77-0007ne-7a for ged-emacs-devel@m.gmane.org; Fri, 29 Jul 2011 13:20:21 +0200 Original-Received: from localhost ([::1]:54425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qml76-0003aB-8s for ged-emacs-devel@m.gmane.org; Fri, 29 Jul 2011 07:20:20 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:33309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qml71-0003Tu-Hr for emacs-devel@gnu.org; Fri, 29 Jul 2011 07:20:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qml6z-0003sd-Tr for emacs-devel@gnu.org; Fri, 29 Jul 2011 07:20:15 -0400 Original-Received: from smarty.dreamhost.com ([208.113.175.8]:59886) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qml6z-0003rx-PX for emacs-devel@gnu.org; Fri, 29 Jul 2011 07:20:13 -0400 Original-Received: from ps18281.dreamhostps.com (ps18281.dreamhost.com [69.163.218.105]) by smarty.dreamhost.com (Postfix) with ESMTP id 6E75F6E8059 for ; Fri, 29 Jul 2011 04:20:13 -0700 (PDT) Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id A5D35451C352 for ; Fri, 29 Jul 2011 04:20:12 -0700 (PDT) In-Reply-To: (Juanma Barranquero's message of "Thu, 28 Jul 2011 16:07:01 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.113.175.8 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:142484 Archived-At: >> Just a tiny patch fixing a problem in goto-line, which was passing a >> string as the second parameter to read-number, triggering an error. > > Committed. I noticed the following areas for improvement: 1. `read-number' already inserts the default value into prompt. So the same code is not necessary in `goto-line'. 2. It would be useful to add the current line number to the defaults of `goto-line' to allow its easier modification by users. This is implemented with: === modified file 'lisp/simple.el' --- lisp/simple.el 2011-07-28 14:05:07 +0000 +++ lisp/simple.el 2011-07-29 11:14:04 +0000 @@ -914,11 +914,8 @@ (defun goto-line (line &optional buffer) (concat " in " (buffer-name buffer)) ""))) ;; Read the argument, offering that number (if any) as default. - (list (read-number (format (if default "Goto line%s (%s): " - "Goto line%s: ") - buffer-prompt - default) - default) + (list (read-number (format "Goto line%s: " buffer-prompt) + (list default (line-number-at-pos))) buffer)))) ;; Switch to the desired buffer, one way or another. (if buffer 3. `read-number' still doesn't support multiple default values like other minibuffer reading functions. Let's do it. === modified file 'lisp/subr.el' --- lisp/subr.el 2011-07-15 23:59:25 +0000 +++ lisp/subr.el 2011-07-29 11:12:45 +0000 @@ -2113,23 +2113,27 @@ (defun read-number (prompt &optional def "Read a numeric value in the minibuffer, prompting with PROMPT. DEFAULT specifies a default value to return if the user just types RET. The value of DEFAULT is inserted into PROMPT." - (let ((n nil)) - (when default + (let ((n nil) + (default1 (if (consp default) (car default) default))) + (when default1 (setq prompt (if (string-match "\\(\\):[ \t]*\\'" prompt) - (replace-match (format " (default %s)" default) t t prompt 1) + (replace-match (format " (default %s)" default1) t t prompt 1) (replace-regexp-in-string "[ \t]*\\'" - (format " (default %s) " default) + (format " (default %s) " default1) prompt t t)))) (while (progn - (let ((str (read-from-minibuffer prompt nil nil nil nil - (and default - (number-to-string default))))) + (let ((str (read-from-minibuffer + prompt nil nil nil nil + (when default + (if (consp default) + (mapcar 'number-to-string (delq nil default)) + (number-to-string default)))))) (condition-case nil (setq n (cond - ((zerop (length str)) default) - ((stringp str) (read str)))) + ((zerop (length str)) default1) + ((stringp str) (string-to-number str)))) (error nil))) (unless (numberp n) (message "Please enter a number.") 4. In the patch above I replaced `read' with `string-to-number' for consistency.