Without changing the source code of etags-select.el , I find it more reasonable, even if it calls find-tag-default twice. You can trick the dynamic environment into a call to avoid repeating the call by memoizing it with something like:
(defun my-etags-find-tag () "Find at point or fall back" (interactive) (let ((ftd (find-tag-default))) (flet ((find-tag-default () ftd)) (if (find-tag-default) (etags-select-find-tag-at-point) (etags-select-find-tag)))))
EDIT : OK, according to your request, an explanation of the code. First, note that this code fulfills both questions:
- This does not fail.
- It is more efficient than the code you show (the one that you say is redundant).
Why is it more effective? The problem with your redundant code is that you call find-tag-default to see if it is nil , and if so, you call etags-select-find-tag-at-point . This function again calls find-tag-default to get the find-tag-default value. What my code does is to cache the find-tag-default value by overriding the function, counting only the calculated value. flet does this, so when etags-select-find-tag-at-point calls find-tag-default , the computed value is returned without further processing.
source share