-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoto-line-faster-1.1.el
65 lines (54 loc) · 2.49 KB
/
goto-line-faster-1.1.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;;; goto-line-faster.el --- Start going to a line number quickly -*- lexical-binding: t -*-
;; Copyright 2020 by Dave Pearson <[email protected]>
;; Author: Dave Pearson <[email protected]>
;; Version: 1.1
;; Keywords: convenience
;; URL: https://github.com/davep/goto-line-faster.el
;; Package-Requires: ((emacs "24") (bind-key "2.0"))
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at your
;; option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
;; Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along
;; with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; goto-line-faster.el provides a utility function that binds M-g followed
;; by a number (1 through 9) to an invocation of goto-line with the number
;; pre-populated in the input in the minibuffer.
;;
;; I wrote this because I've never liked 'M-g g' as a way to go to a line
;; number, but I'd like to use some of the other M-g-prefixed key bindings
;; too. This pretty much gives me the best of both worlds.
;;
;; Please note that this version of the code is very different from the
;; original version, with <URL:https://github.com/phil-s> providing a much
;; cleaner approach.
;;; Code:
(require 'bind-key)
;;;###autoload
(defun goto-line-faster (_)
"Slightly faster `goto-line' for those with particular muscle memory.
This command is designed to be bound to the goto prefix key
combination followed by the numbers 1 through 9, to give the
effect of simply hitting the goto prefix combination and starting
to type a line number. The result is that `goto-line' is called
with the minibuffer prepopulated with the relevant value.
This command is likely of little utility to anyone who doesn't
have this particular muscle memory."
(interactive "P")
(when (and (<= ?1 last-command-event ?9) (not (numberp current-prefix-arg)))
(push last-command-event unread-command-events))
(call-interactively #'goto-line))
;; Set up quick goto-line bindings for line numbers that start with 1
;; through 9...
(dotimes (n 9)
(bind-key (format "M-g %s" (1+ n)) #'goto-line-faster))
(provide 'goto-line-faster)
;;; goto-line-faster.el ends here