-
Notifications
You must be signed in to change notification settings - Fork 0
/
goto-line-faster-1.0.el
57 lines (47 loc) · 2.18 KB
/
goto-line-faster-1.0.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
;;; goto-line-faster.el --- Start going to a line number quickly -*- lexical-binding: t -*-
;; Copyright 2020 by Dave Pearson <davep@davep.org>
;; Author: Dave Pearson <davep@davep.org>
;; Version: 1.0
;; 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.
;;; Code:
(require 'bind-key)
(defun goto-line-faster--maker (prefix)
"Create an interactive function to start going to a line.
The line number that we'll go to will start with PREFIX."
(let ((name (intern (format "goto-line-faster-%s" prefix))))
(prog1
(defalias name
(lambda ()
(interactive)
(setq unread-command-events (listify-key-sequence (number-to-string prefix)))
(command-execute #'goto-line)))
(setf (get name 'function-documentation) (format "Go to a line whose number starts with %s." prefix)))))
;; 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--maker (1+ n))))
(provide 'goto-line-faster)
;;; goto-line-faster.el ends here