diff options
| author | Richard M. Stallman | 2005-03-05 18:02:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-03-05 18:02:40 +0000 |
| commit | 00a369aca266f18f561df5848c64b26538519e97 (patch) | |
| tree | ff15b1d8f920b06ce993000fdeb883ae46dfeff7 | |
| parent | d21783879a16cdf208f28a67fe6d275a317c3a68 (diff) | |
| download | emacs-00a369aca266f18f561df5848c64b26538519e97.tar.gz emacs-00a369aca266f18f561df5848c64b26538519e97.zip | |
(goto-line): Use a number at point as the default.
With C-u as arg, switch buffers.
| -rw-r--r-- | lisp/simple.el | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 3d3178888bc..67d3bc6b8e8 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -733,16 +733,54 @@ that uses or sets the mark." | |||
| 733 | 733 | ||
| 734 | ;; Counting lines, one way or another. | 734 | ;; Counting lines, one way or another. |
| 735 | 735 | ||
| 736 | (defun goto-line (arg) | 736 | (defun goto-line (arg &optional buffer) |
| 737 | "Goto line ARG, counting from line 1 at beginning of buffer." | 737 | "Goto line ARG, counting from line 1 at beginning of buffer. |
| 738 | (interactive "NGoto line: ") | 738 | Normally, move point in the curren buffer. |
| 739 | (setq arg (prefix-numeric-value arg)) | 739 | With just C-u as argument, move point in the most recently displayed |
| 740 | other buffer, and switch to it. | ||
| 741 | |||
| 742 | If there's a number in the buffer at point, it is the default for ARG." | ||
| 743 | (interactive | ||
| 744 | (if (and current-prefix-arg (not (consp current-prefix-arg))) | ||
| 745 | (list (prefix-numeric-value current-prefix-arg)) | ||
| 746 | ;; Look for a default, a number in the buffer at point. | ||
| 747 | (let* ((default | ||
| 748 | (save-excursion | ||
| 749 | (skip-chars-backward "0-9") | ||
| 750 | (if (looking-at "[0-9]") | ||
| 751 | (buffer-substring-no-properties | ||
| 752 | (point) | ||
| 753 | (progn (skip-chars-forward "0-9") | ||
| 754 | (point)))))) | ||
| 755 | ;; Decide if we're switching buffers. | ||
| 756 | (buffer | ||
| 757 | (if (consp current-prefix-arg) | ||
| 758 | (other-buffer (current-buffer) t))) | ||
| 759 | (buffer-prompt | ||
| 760 | (if buffer | ||
| 761 | (concat " in " (buffer-name buffer)) | ||
| 762 | ""))) | ||
| 763 | ;; Read the argument, offering that number (if any) as default. | ||
| 764 | (list (read-from-minibuffer (format (if default "Goto line%s (%s): " | ||
| 765 | "Goto line%s: ") | ||
| 766 | buffer-prompt | ||
| 767 | default) | ||
| 768 | nil nil t | ||
| 769 | 'minibuffer-history | ||
| 770 | default) | ||
| 771 | buffer)))) | ||
| 772 | ;; Switch to the desired buffer, one way or another. | ||
| 773 | (if buffer | ||
| 774 | (let ((window (get-buffer-window buffer))) | ||
| 775 | (if window (select-window window) | ||
| 776 | (switch-to-buffer-other-window buffer)))) | ||
| 777 | ;; Move to the specified line number in that buffer. | ||
| 740 | (save-restriction | 778 | (save-restriction |
| 741 | (widen) | 779 | (widen) |
| 742 | (goto-char 1) | 780 | (goto-char 1) |
| 743 | (if (eq selective-display t) | 781 | (if (eq selective-display t) |
| 744 | (re-search-forward "[\n\C-m]" nil 'end (1- arg)) | 782 | (re-search-forward "[\n\C-m]" nil 'end (1- arg)) |
| 745 | (forward-line (1- arg))))) | 783 | (forward-line (1- arg)))))) |
| 746 | 784 | ||
| 747 | (defun count-lines-region (start end) | 785 | (defun count-lines-region (start end) |
| 748 | "Print number of lines and characters in the region." | 786 | "Print number of lines and characters in the region." |