org-ctags.el: Define unload function
* lisp/org-ctags.el (org-ctags-unload-function): New function to cleanup during `unload-feature' call. (org-ctags--open-link-functions-list org-ctags-open-link-functions): Define and use list of options available for `org-open-link-functions'. (org-ctags--visit-tags-table): Give a name to remove the function from `org-mode-hook' on library unload. Prevent the following error after library unloading Symbol’s function definition is void: org-ctags-find-tag
This commit is contained in:
parent
3e11b2eb88
commit
735334445f
|
@ -161,6 +161,20 @@ See the ctags documentation for more information.")
|
||||||
:version "24.1"
|
:version "24.1"
|
||||||
:type 'file)
|
:type 'file)
|
||||||
|
|
||||||
|
(defconst org-ctags--open-link-functions-list
|
||||||
|
(list
|
||||||
|
#'org-ctags-find-tag
|
||||||
|
#'org-ctags-ask-rebuild-tags-file-then-find-tag
|
||||||
|
#'org-ctags-rebuild-tags-file-then-find-tag
|
||||||
|
#'org-ctags-ask-append-topic
|
||||||
|
#'org-ctags-append-topic
|
||||||
|
#'org-ctags-ask-visit-buffer-or-file
|
||||||
|
#'org-ctags-visit-buffer-or-file
|
||||||
|
#'org-ctags-fail-silently)
|
||||||
|
"Options for `org-open-link-functions'.
|
||||||
|
Ensure that the user option and `unload-feature'
|
||||||
|
use the same set of functions.")
|
||||||
|
|
||||||
(defcustom org-ctags-open-link-functions
|
(defcustom org-ctags-open-link-functions
|
||||||
'(org-ctags-find-tag
|
'(org-ctags-find-tag
|
||||||
org-ctags-ask-rebuild-tags-file-then-find-tag
|
org-ctags-ask-rebuild-tags-file-then-find-tag
|
||||||
|
@ -168,14 +182,7 @@ See the ctags documentation for more information.")
|
||||||
"List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS by ORG-CTAGS."
|
"List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS by ORG-CTAGS."
|
||||||
:version "24.1"
|
:version "24.1"
|
||||||
:type 'hook
|
:type 'hook
|
||||||
:options '(org-ctags-find-tag
|
:options org-ctags--open-link-functions-list)
|
||||||
org-ctags-ask-rebuild-tags-file-then-find-tag
|
|
||||||
org-ctags-rebuild-tags-file-then-find-tag
|
|
||||||
org-ctags-ask-append-topic
|
|
||||||
org-ctags-append-topic
|
|
||||||
org-ctags-ask-visit-buffer-or-file
|
|
||||||
org-ctags-visit-buffer-or-file
|
|
||||||
org-ctags-fail-silently))
|
|
||||||
|
|
||||||
|
|
||||||
(defvar org-ctags-tag-list nil
|
(defvar org-ctags-tag-list nil
|
||||||
|
@ -191,18 +198,20 @@ The following patterns are replaced in the string:
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
|
|
||||||
(add-hook 'org-mode-hook
|
(defun org-ctags--visit-tags-table ()
|
||||||
(lambda ()
|
"Load tags for current file.
|
||||||
(when (and org-ctags-enabled-p
|
A function for `org-mode-hook."
|
||||||
(buffer-file-name))
|
(when (and org-ctags-enabled-p
|
||||||
;; Make sure this file's directory is added to default
|
(buffer-file-name))
|
||||||
;; directories in which to search for tags.
|
;; Make sure this file's directory is added to default
|
||||||
(let ((tags-filename
|
;; directories in which to search for tags.
|
||||||
(expand-file-name
|
(let ((tags-filename
|
||||||
(concat (file-name-directory (buffer-file-name))
|
(expand-file-name
|
||||||
"/TAGS"))))
|
(concat (file-name-directory (buffer-file-name))
|
||||||
(when (file-exists-p tags-filename)
|
"/TAGS"))))
|
||||||
(visit-tags-table tags-filename))))))
|
(when (file-exists-p tags-filename)
|
||||||
|
(visit-tags-table tags-filename)))))
|
||||||
|
(add-hook 'org-mode-hook #'org-ctags--visit-tags-table)
|
||||||
|
|
||||||
|
|
||||||
(advice-add 'visit-tags-table :after #'org--ctags-load-tag-list)
|
(advice-add 'visit-tags-table :after #'org--ctags-load-tag-list)
|
||||||
|
@ -219,6 +228,17 @@ The following patterns are replaced in the string:
|
||||||
(add-hook 'org-open-link-functions fn t)))
|
(add-hook 'org-open-link-functions fn t)))
|
||||||
|
|
||||||
|
|
||||||
|
(defun org-ctags-unload-function ()
|
||||||
|
"Disable `org-ctags' library.
|
||||||
|
Called by `unload-feature'."
|
||||||
|
(put 'org-mode 'find-tag-default-function nil)
|
||||||
|
(advice-remove 'visit-tags-table #'org--ctags-load-tag-list)
|
||||||
|
(advice-remove 'xref-find-definitions
|
||||||
|
#'org--ctags-set-org-mark-before-finding-tag)
|
||||||
|
(dolist (fn org-ctags--open-link-functions-list)
|
||||||
|
(remove-hook 'org-open-link-functions fn nil)))
|
||||||
|
|
||||||
|
|
||||||
;;; General utility functions. ===============================================
|
;;; General utility functions. ===============================================
|
||||||
;; These work outside org-ctags mode.
|
;; These work outside org-ctags mode.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue