FUEL: New option fuel-xref-follow-link-method (current buffer, new window or frame).

db4
Jose A. Ortega Ruiz 2009-01-22 09:55:39 +01:00
parent fc658411fa
commit 4a5d8f5344
2 changed files with 30 additions and 14 deletions

View File

@ -22,17 +22,26 @@
;;; Customization ;;; Customization
(defcustom fuel-edit-word-method nil (defmacro fuel-edit--define-custom-visit (var group doc)
"How the new buffer is opened when invoking `(defcustom ,var nil
\\[fuel-edit-word-at-point]." ,doc
:group 'fuel :group ',group
:type '(choice (const :tag "Other window" window) :type '(choice (const :tag "Other window" window)
(const :tag "Other frame" frame) (const :tag "Other frame" frame)
(const :tag "Current window" nil))) (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: ;;; 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 () (defun fuel-edit--looking-at-vocab ()
(save-excursion (save-excursion
(fuel-syntax--beginning-of-defun) (fuel-syntax--beginning-of-defun)
@ -45,9 +54,7 @@
(error "Couldn't find edit location")) (error "Couldn't find edit location"))
(unless (file-readable-p (car loc)) (unless (file-readable-p (car loc))
(error "Couldn't open '%s' for read" (car loc))) (error "Couldn't open '%s' for read" (car loc)))
(cond ((eq fuel-edit-word-method 'window) (find-file-other-window (car loc))) (fuel-edit--visit-file (car loc) fuel-edit-word-method)
((eq fuel-edit-word-method 'frame) (find-file-other-frame (car loc)))
(t (find-file (car loc))))
(goto-line (if (numberp (cadr loc)) (cadr loc) 1)))) (goto-line (if (numberp (cadr loc)) (cadr loc) 1))))
(defun fuel-edit--read-vocabulary-name (refresh) (defun fuel-edit--read-vocabulary-name (refresh)

View File

@ -37,6 +37,11 @@ cursor at the first ocurrence of the used word."
:group 'fuel-xref :group 'fuel-xref
:type 'boolean) :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 (fuel-font-lock--defface fuel-font-lock-xref-link
'link fuel-xref "highlighting links in cross-reference buffers") '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)) (when (not (file-readable-p file))
(error "File '%s' is not readable" file)) (error "File '%s' is not readable" file))
(let ((word fuel-xref--word)) (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 (numberp line) (goto-line line))
(when (and word fuel-xref-follow-link-to-word-p) (when (and word fuel-xref-follow-link-to-word-p)
(and (search-forward word (and (re-search-forward (format "\\_<%s\\_>" word)
(fuel-syntax--end-of-defun-pos) (fuel-syntax--end-of-defun-pos)
t) t)
(goto-char (match-beginning 0))))))) (goto-char (match-beginning 0)))))))
@ -126,21 +131,25 @@ cursor at the first ocurrence of the used word."
(defun fuel-xref--show-callers (word) (defun fuel-xref--show-callers (word)
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref)))) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (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))) (fuel-xref--fill-and-display word "using" res)))
(defun fuel-xref--show-callees (word) (defun fuel-xref--show-callees (word)
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref)))) (let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (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))) (fuel-xref--fill-and-display word "used by" res)))
(defun fuel-xref--apropos (str) (defun fuel-xref--apropos (str)
(let* ((cmd `(:fuel* ((,str fuel-apropos-xref)))) (let* ((cmd `(:fuel* ((,str fuel-apropos-xref))))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (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))) (fuel-xref--fill-and-display str "containing" res)))
(defun fuel-xref--show-vocab (vocab &optional app) (defun fuel-xref--show-vocab (vocab &optional app)
(let* ((cmd `(:fuel* ((,vocab fuel-vocab-xref)) ,vocab)) (let* ((cmd `(:fuel* ((,vocab fuel-vocab-xref)) ,vocab))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (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))) (fuel-xref--fill-buffer vocab "in vocabulary" res t app)))
(defun fuel-xref--show-vocab-words (vocab &optional private) (defun fuel-xref--show-vocab-words (vocab &optional private)