-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmagit-ido.el
More file actions
100 lines (83 loc) · 3.66 KB
/
Copy pathmagit-ido.el
File metadata and controls
100 lines (83 loc) · 3.66 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; magit-ido.el --- Support using Ido in Magit -*- lexical-binding:t -*-
;; Copyright (C) 2025 The Magit Project Contributors
;; Author: Jonas Bernoulli <emacs.magit-ido@jonas.bernoulli.dev>
;; Maintainer: Jonas Bernoulli <emacs.magit-ido@jonas.bernoulli.dev>
;; Homepage: https://github.com/emacsorphanage/magit-ido
;; Package-Version: 1.0.0
;; Package-Requires: ((ido-completing-read+ "4.14") (magit "4.3.2"))
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Magit 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.
;;
;; Magit 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 Magit. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package adds support for using Ido in Magit. For the most part
;; it was extracted from code that was previously part of Magit itself.
;; To enable Ido support, you need to add something like this to your
;; init file:
;;
;; (with-eval-after-load 'magit
;; (require 'magit-ido)
;; (setq magit-completing-read-function
;; 'magit-ido-completing-read)
;; ;; Optional:
;; (keymap-set ido-common-completion-map
;; "C-x g" 'magit-ido-enter-magit-status))
;;; Code:
(require 'magit)
(require 'ido-completing-read+)
(defun magit-ido-completing-read
(prompt choices &optional predicate require-match initial-input hist def)
"Ido-based `completing-read' almost-replacement.
Unfortunately `ido-completing-read' itself is not suitable as a drop-in
replacement for `completing-read'; instead we use `ido-completing-read+'
from the third-party package by the same name."
(ido-completing-read+ prompt choices predicate require-match
initial-input hist
(or def (and require-match (car choices)))))
(define-advice magit-submodule-read-path
(:override (prompt url) magit-ido)
"Prevent use of Ido because it is broken for this use case.
`ido-read-file-name' does not work here, so force the use of
`read-file-name-default'."
(directory-file-name
(file-relative-name
(let ((read-file-name-function #'read-file-name-default))
(read-directory-name prompt nil nil nil
(and (string-match "\\([^./]+\\)\\(\\.git\\)?$" url)
(match-string 1 url)))))))
(define-advice magit-subtree-read-prefix
(:override (prompt &optional default _history) magit-ido)
"Prevent use of Ido because it is broken for this use case.
`ido-read-file-name' does not work here, so force the use of
`read-file-name-default'."
(let* ((insert-default-directory nil)
(topdir (magit-toplevel))
(read-file-name-function #'read-file-name-default)
(prefix (read-directory-name (concat prompt ": ") topdir default)))
(if (file-name-absolute-p prefix)
(if (string-prefix-p topdir prefix)
(file-relative-name prefix topdir)
(user-error "%s isn't inside the repository at %s" prefix topdir))
prefix)))
(defvar ido-exit)
(defvar ido-fallback)
(defun magit-ido-enter-magit-status ()
"Drop into the `magit-status' buffer from Ido file switching."
(interactive)
(setq ido-exit 'fallback)
(setq ido-fallback #'magit-status)
(exit-minibuffer))
(provide 'magit-ido)
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
;;; magit-ido.el ends here