branch: scratch/rfc-mode commit ff7a36b81047892240d70fddd25e4e36d3434345 Author: Daniel MartÃn <mardan...@yahoo.es> Commit: Nicolas Martyanoff <khae...@gmail.com>
Offer number at point as default in rfc-mode-read * rfc-mode.el (rfc-mode-read): Try to get a number under point and offer it as default when read-number is called. * changelog.org (Features): Advertise the new feature. --- changelog.org | 4 +++- rfc-mode.el | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/changelog.org b/changelog.org index a4809a476c..d2414cb4ef 100644 --- a/changelog.org +++ b/changelog.org @@ -5,7 +5,9 @@ ** Features - ~rfc-mode-read~ now supports a numeric prefix argument, so you can - simply type ~C-u 1 2 3 4 M-x rfc-mode-read~ to read RFC number 1234. + simply type ~C-u 1 2 3 4 M-x rfc-mode-read~ to read RFC + number 1234. Also, if you call ~rfc-mode-read~ when point is on a + number, you will be offered that number as default. * 1.3.0 This release improves navigation and introduce section detection, thanks to diff --git a/rfc-mode.el b/rfc-mode.el index 5214055276..cce1d3b01c 100644 --- a/rfc-mode.el +++ b/rfc-mode.el @@ -196,11 +196,24 @@ Returns t if section is found, nil otherwise." ;;;###autoload (defun rfc-mode-read (number) - "Read the RFC document NUMBER." + "Read the RFC document NUMBER. +Offer the number at point as default." (interactive (if (and current-prefix-arg (not (consp current-prefix-arg))) (list (prefix-numeric-value current-prefix-arg)) - (list (read-number "RFC number: ")))) + (let ((default + ;; Note that we don't use `number-at-point' as it will + ;; match number formats that make no sense as RFC numbers + ;; (floating point, hexadecimal, etc.). + (save-excursion + (skip-chars-backward "0-9") + (if (looking-at "[0-9]") + (string-to-number + (buffer-substring-no-properties + (point) + (progn (skip-chars-forward "0-9") + (point)))))))) + (list (read-number "RFC number: " default))))) (display-buffer (rfc-mode--document-buffer number))) (defun rfc-mode-reload-index ()