Skip to content

Commit 959bbf3

Browse files
committed
Add unload code to tramp-integration.el
* lisp/net/tramp-integration.el (info-lookup->mode-cache) (info-lookup->topic-cache, info-lookup-alist): Declare. (ido, ivy, info-look): Adapt `tramp-integration-unload-hook'.
1 parent 3403d7a commit 959bbf3

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

lisp/net/tramp-integration.el

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
;; Pacify byte-compiler.
3333
(require 'cl-lib)
3434
(declare-function info-lookup->cache "info-look")
35+
(declare-function info-lookup->mode-cache "info-look")
3536
(declare-function info-lookup->mode-value "info-look")
3637
(declare-function info-lookup->other-modes "info-look")
38+
(declare-function info-lookup->topic-cache "info-look")
3739
(declare-function info-lookup->topic-value "info-look")
3840
(declare-function info-lookup-maybe-add-help "info-look")
3941
(declare-function recentf-cleanup "recentf")
@@ -42,7 +44,7 @@
4244
(declare-function tramp-tramp-file-p "tramp")
4345
(defvar eshell-path-env)
4446
(defvar ido-read-file-name-non-ido)
45-
(defvar info-lookup-cache)
47+
(defvar info-lookup-alist)
4648
(defvar ivy-completing-read-handlers-alist)
4749
(defvar recentf-exclude)
4850
(defvar tramp-current-connection)
@@ -182,15 +184,32 @@ NAME must be equal to `tramp-current-connection'."
182184

183185
(with-eval-after-load 'ido
184186
(add-to-list 'ido-read-file-name-non-ido 'tramp-rename-files)
185-
(add-to-list 'ido-read-file-name-non-ido 'tramp-these-rename-files))
187+
(add-to-list 'ido-read-file-name-non-ido 'tramp-these-rename-files)
188+
(add-hook 'tramp-integration-unload-hook
189+
(lambda ()
190+
(setq ido-read-file-name-non-ido
191+
(delq 'tramp-these-rename-files ido-read-file-name-non-ido)
192+
ido-read-file-name-non-ido
193+
(delq 'tramp-rename-files ido-read-file-name-non-ido)))))
186194

187195
;;; Integration of ivy.el:
188196

189197
(with-eval-after-load 'ivy
190198
(add-to-list 'ivy-completing-read-handlers-alist
191199
'(tramp-rename-files . completing-read-default))
192200
(add-to-list 'ivy-completing-read-handlers-alist
193-
'(tramp-these-rename-files . completing-read-default)))
201+
'(tramp-these-rename-files . completing-read-default))
202+
(add-hook
203+
'tramp-integration-unload-hook
204+
(lambda ()
205+
(setq ivy-completing-read-handlers-alist
206+
(delete
207+
(assq 'tramp-these-rename-files ivy-completing-read-handlers-alist)
208+
ivy-completing-read-handlers-alist)
209+
ivy-completing-read-handlers-alist
210+
(delete
211+
(assq 'tramp-rename-files ivy-completing-read-handlers-alist)
212+
ivy-completing-read-handlers-alist)))))
194213

195214
;;; Integration of info-look.el:
196215

@@ -202,24 +221,45 @@ NAME must be equal to `tramp-current-connection'."
202221
:doc-spec '(("(tramp)Function Index" nil "^ -+ .*: " "\\( \\|$\\)")
203222
("(tramp)Variable Index" nil "^ -+ .*: " "\\( \\|$\\)")))
204223

205-
;; Add it as `other-modes' to `emacs-lisp-mode' itself, and all
206-
;; modes which use it as `other-modes'.
224+
(add-hook
225+
'tramp-integration-unload-hook
226+
(lambda ()
227+
(setcdr (assq 'symbol info-lookup-alist)
228+
(delete (info-lookup->mode-value 'symbol 'tramp-info-lookup-mode)
229+
(info-lookup->topic-value 'symbol)))
230+
(setcdr (info-lookup->cache 'symbol)
231+
(delete (info-lookup->mode-cache 'symbol 'tramp-info-lookup-mode)
232+
(info-lookup->topic-cache 'symbol)))))
233+
207234
(dolist (mode (mapcar 'car (info-lookup->topic-value 'symbol)))
235+
;; Add `tramp-info-lookup-mode' to `other-modes' for either
236+
;; `emacs-lisp-mode' itself, or to modes which use
237+
;; `emacs-lisp-mode' as `other-modes'. Reset `info-lookup-cache'.
208238
(when (and (or (equal mode 'emacs-lisp-mode)
209-
(member
239+
(memq
210240
'emacs-lisp-mode (info-lookup->other-modes 'symbol mode)))
211-
(not (member
212-
'tramp-info-lookup-mode
213-
(info-lookup->other-modes 'symbol mode))))
214-
(setcdr
215-
(info-lookup->mode-value 'symbol mode)
216-
(append
217-
(butlast (cdr (info-lookup->mode-value 'symbol mode)))
218-
`(,(cons 'tramp-info-lookup-mode
219-
(info-lookup->other-modes 'symbol mode)))))))
220-
221-
;; Reset cache.
222-
(setq info-lookup-cache nil))
241+
(not (memq 'tramp-info-lookup-mode
242+
(info-lookup->other-modes 'symbol mode))))
243+
(setcdr (info-lookup->mode-value 'symbol mode)
244+
(append (butlast (cdr (info-lookup->mode-value 'symbol mode)))
245+
`((tramp-info-lookup-mode
246+
. ,(info-lookup->other-modes 'symbol mode)))))
247+
(setcdr (info-lookup->cache 'symbol)
248+
(delete (info-lookup->mode-cache 'symbol mode)
249+
(info-lookup->topic-cache 'symbol)))
250+
251+
(add-hook
252+
'tramp-integration-unload-hook
253+
`(lambda ()
254+
(setcdr (info-lookup->mode-value 'symbol ',mode)
255+
(append (butlast
256+
(cdr (info-lookup->mode-value 'symbol ',mode)))
257+
(list
258+
(delq 'tramp-info-lookup-mode
259+
(info-lookup->other-modes 'symbol ',mode)))))
260+
(setcdr (info-lookup->cache 'symbol)
261+
(delete (info-lookup->mode-cache 'symbol ',mode)
262+
(info-lookup->topic-cache 'symbol))))))))
223263

224264
;;; Default connection-local variables for Tramp:
225265

0 commit comments

Comments
 (0)