diff --git a/misc/fuel/fuel-edit.el b/misc/fuel/fuel-edit.el index 0334ab6104..484fed66cd 100644 --- a/misc/fuel/fuel-edit.el +++ b/misc/fuel/fuel-edit.el @@ -22,17 +22,26 @@ ;;; Customization -(defcustom fuel-edit-word-method nil - "How the new buffer is opened when invoking -\\[fuel-edit-word-at-point]." - :group 'fuel - :type '(choice (const :tag "Other window" window) - (const :tag "Other frame" frame) - (const :tag "Current window" nil))) +(defmacro fuel-edit--define-custom-visit (var group doc) + `(defcustom ,var nil + ,doc + :group ',group + :type '(choice (const :tag "Other window" window) + (const :tag "Other frame" frame) + (const :tag "Current window" nil)))) + +(fuel-edit--define-custom-visit + fuel-edit-word-method fuel + "How the new buffer is opened when invoking \\[fuel-edit-word-at-point]") ;;; Auxiliar functions: +(defun fuel-edit--visit-file (file method) + (cond ((eq method 'window) (find-file-other-window file)) + ((eq method 'frame) (find-file-other-frame file)) + (t (find-file file)))) + (defun fuel-edit--looking-at-vocab () (save-excursion (fuel-syntax--beginning-of-defun) @@ -45,9 +54,7 @@ (error "Couldn't find edit location")) (unless (file-readable-p (car loc)) (error "Couldn't open '%s' for read" (car loc))) - (cond ((eq fuel-edit-word-method 'window) (find-file-other-window (car loc))) - ((eq fuel-edit-word-method 'frame) (find-file-other-frame (car loc))) - (t (find-file (car loc)))) + (fuel-edit--visit-file (car loc) fuel-edit-word-method) (goto-line (if (numberp (cadr loc)) (cadr loc) 1)))) (defun fuel-edit--read-vocabulary-name (refresh) diff --git a/misc/fuel/fuel-xref.el b/misc/fuel/fuel-xref.el index f754c626f7..d98c0b0a69 100644 --- a/misc/fuel/fuel-xref.el +++ b/misc/fuel/fuel-xref.el @@ -37,6 +37,11 @@ cursor at the first ocurrence of the used word." :group 'fuel-xref :type 'boolean) +(fuel-edit--define-custom-visit + fuel-xref-follow-link-method + fuel-xref + "How new buffers are opened when following a crossref link.") + (fuel-font-lock--defface fuel-font-lock-xref-link 'link fuel-xref "highlighting links in cross-reference buffers") @@ -59,12 +64,12 @@ cursor at the first ocurrence of the used word." (when (not (file-readable-p file)) (error "File '%s' is not readable" file)) (let ((word fuel-xref--word)) - (find-file-other-window file) + (fuel-edit--visit-file file fuel-xref-follow-link-method) (when (numberp line) (goto-line line)) (when (and word fuel-xref-follow-link-to-word-p) - (and (search-forward word - (fuel-syntax--end-of-defun-pos) - t) + (and (re-search-forward (format "\\_<%s\\_>" word) + (fuel-syntax--end-of-defun-pos) + t) (goto-char (match-beginning 0))))))) @@ -126,21 +131,25 @@ cursor at the first ocurrence of the used word." (defun fuel-xref--show-callers (word) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) + (with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word word)) (fuel-xref--fill-and-display word "using" res))) (defun fuel-xref--show-callees (word) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) + (with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word nil)) (fuel-xref--fill-and-display word "used by" res))) (defun fuel-xref--apropos (str) (let* ((cmd `(:fuel* ((,str fuel-apropos-xref)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) + (with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word nil)) (fuel-xref--fill-and-display str "containing" res))) (defun fuel-xref--show-vocab (vocab &optional app) (let* ((cmd `(:fuel* ((,vocab fuel-vocab-xref)) ,vocab)) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) + (with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word nil)) (fuel-xref--fill-buffer vocab "in vocabulary" res t app))) (defun fuel-xref--show-vocab-words (vocab &optional private)