summaryrefslogtreecommitdiff
path: root/lisp/minibuffer.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-10-01 15:01:52 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-10-01 15:01:57 +0200
commit4861328f2a0b95adfb36885db645f5a87ddda7ea (patch)
tree337bee0ef64629992dd92daae8e39abf91c59f13 /lisp/minibuffer.el
parentcdc440f0b62362fd38e91e2099919d57fef06436 (diff)
downloademacs-4861328f2a0b95adfb36885db645f5a87ddda7ea.tar.gz
Allow 'M-<' in the minibuffer to behave more logically
* doc/lispref/minibuf.texi (Completion Commands) (Text from Minibuffer): Document it. * lisp/minibuffer.el (minibuffer-beginning-of-buffer): New command (bug#3447). (map): Bind it.
Diffstat (limited to 'lisp/minibuffer.el')
-rw-r--r--lisp/minibuffer.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 3fa637f2acd..7227e83f878 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2233,6 +2233,7 @@ The completion method is determined by `completion-at-point-functions'."
(let ((map minibuffer-local-map))
(define-key map "\C-g" 'abort-recursive-edit)
+ (define-key map "\M-<" 'minibuffer-beginning-of-buffer)
(define-key map "\r" 'exit-minibuffer)
(define-key map "\n" 'exit-minibuffer))
@@ -2529,6 +2530,14 @@ such as making the current buffer visit no file in the case of
`set-visited-file-name'."
:type 'boolean)
+(defcustom minibuffer-beginning-of-buffer-movement nil
+ "Control how the `M-<' command in the minibuffer behaves.
+If non-nil, the command will go to the end of the prompt (if
+point is after the end of the prompt). If nil, it will behave
+like the `beginning-of-buffer' command."
+ :version "27.1"
+ :type 'boolean)
+
;; Not always defined, but only called if next-read-file-uses-dialog-p says so.
(declare-function x-file-dialog "xfns.c"
(prompt dir &optional default-filename mustmatch only-dir-p))
@@ -3589,6 +3598,33 @@ See `completing-read' for the meaning of the arguments."
(when file-name-at-point
(insert file-name-at-point))))
+(defun minibuffer-beginning-of-buffer (&optional arg)
+ "Move to the logical beginning of the minibuffer.
+This command behaves like `beginning-of-buffer', but if point is
+after the end of the prompt, move to the end of the prompt.
+Otherwise move to the start of the buffer."
+ (declare (interactive-only "use `(goto-char (point-min))' instead."))
+ (interactive "^P")
+ (when (or (consp arg)
+ (region-active-p))
+ (push-mark))
+ (goto-char (cond
+ ;; We want to go N/10th of the way from the beginning.
+ ((and arg (not (consp arg)))
+ (+ (point-min) 1
+ (/ (* (- (point-max) (point-min))
+ (prefix-numeric-value arg))
+ 10)))
+ ;; Go to the start of the buffer.
+ ((or (null minibuffer-beginning-of-buffer-movement)
+ (<= (point) (minibuffer-prompt-end)))
+ (point-min))
+ ;; Go to the end of the minibuffer.
+ (t
+ (minibuffer-prompt-end))))
+ (when (and arg (not (consp arg)))
+ (forward-line 1)))
+
(provide 'minibuffer)
;;; minibuffer.el ends here