emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Key binding M-g should really be goto-line autolearn=noversion=3.0.2


From: Richard Stallman
Subject: Re: Key binding M-g should really be goto-line autolearn=noversion=3.0.2 autolearn=no version=3.0.2
Date: Fri, 04 Mar 2005 18:45:32 -0500

How about making goto-line suggest the number at point
as its default argument?


(defun goto-line (arg &optional buffer)
  "Goto line ARG, counting from line 1 at beginning of buffer.
With just C-u as argument, move point in the most recently displayed
other buffer, and display it."
  (interactive
   (if (and current-prefix-arg (not (consp current-prefix-arg)))
       (list (prefix-numeric-value current-prefix-arg))
     ;; Look for a default, a number in the buffer at point.
     (let ((default
             (save-excursion
               (skip-chars-backward "0-9")
               (if (looking-at "[0-9]")
                   (buffer-substring-no-properties
                    (point)
                    (progn (skip-chars-forward "0-9")
                           (point)))))))
       ;; Read the argument, offering that number (if any) default.
       (list (read-from-minibuffer (format "Goto line (%s): " default)
                                   nil nil t
                                   'minibuffer-history
                                   default)
             (if (consp current-prefix-arg)
                 (other-buffer (current-buffer) t))))))
  (with-current-buffer (or buffer (current-buffer))
    (save-restriction
      (widen)
      (goto-char 1)
      (if (eq selective-display t)
          (re-search-forward "[\n\C-m]" nil 'end (1- arg))
        (forward-line (1- arg)))
      (if buffer
          (let ((window (get-buffer-window buffer)))
            (if window
                (set-window-point window (point))
              (display-buffer buffer)))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]