From: Juri Linkov <juri@jurta.org>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] fix goto-line
Date: Fri, 29 Jul 2011 14:15:33 +0300 [thread overview]
Message-ID: <8762ml5odm.fsf@mail.jurta.org> (raw)
In-Reply-To: <CAAeL0SRh3H8CPGgNFfSJgjH9rdPoZZS4AG6gemxEGRnXwwK-zw@mail.gmail.com> (Juanma Barranquero's message of "Thu, 28 Jul 2011 16:07:01 +0200")
>> 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.
next prev parent reply other threads:[~2011-07-29 11:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-28 12:57 [PATCH] fix goto-line Jose E. Marchesi
2011-07-28 14:07 ` Juanma Barranquero
2011-07-28 17:38 ` bug#9163: " Eduard Wiebe
2011-07-28 17:38 ` Eduard Wiebe
2011-07-29 11:15 ` Juri Linkov [this message]
2011-07-29 11:22 ` Juanma Barranquero
2011-07-29 15:28 ` Juri Linkov
2011-07-29 16:45 ` Paul Eggert
2011-07-30 9:17 ` dired-do-touch (was: [PATCH] fix goto-line) Juri Linkov
2011-07-30 9:50 ` dired-do-touch Juri Linkov
2011-07-30 9:54 ` dired-do-touch (was: [PATCH] fix goto-line) Andreas Schwab
2011-07-30 11:01 ` dired-do-touch Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8762ml5odm.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.