I want to create a modified copy of re-search-forward
and advise this copy to be sensitive to isearch-filter-predicate
. I tried:
(defun make-search-sensitive-to-ifpmod-advice (orig-fun &rest args)
"Temporary advice the search functions to make them sensitive to
`isearch-filter-predicate'"
(let ((POINT (point)))
(catch 'filtered
(while (apply orig-fun args)
(let ((B (match-beginning 0))
(E (match-end 0)))
;; 1 - If all points in the region that matches the search
;; from the previous "search-command" meet the criteria
;; accepted by the filter, then the loop stops (`throw') and
;; returns the position `(point)`:
(when (funcall isearch-filter-predicate B E)
(throw 'filtered (point)))))
;; 2 - If the search is unsuccessful, or does not meet
;; the criteria accepted by the filter, then return to the
;; starting position and return the value `nil'.
(goto-char POINT)
nil)))
(defalias 're-search-forward-ifpmod
(symbol-function 're-search-forward)
"Copy of `re-search-forward' function (to be) adviced to obey to
`isearch-filter-predicate'")
(defalias 'search-forward-regexp-ifpmod 're-search-forward-ifpmod)
(advice-add 're-search-forward-ifpmod
:around
#'make-search-sensitive-to-ifpmod-advice)
I tested this code and it works but it generates a strange bug: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69573
Eager macro-expansion failure: (wrong-type-argument integer-or-marker-p nil)
So my question is (regardless of the bug and the issue I mentioned above): Does the usage of defalias
combined with symbol-function
create an "independent" copy (not an alias) of the original function? If not, how to do that?
Note added. By "independent copy," I mean that a modification, such as an advice, to the original function should not affect the copy of that function. Let's take this code as an example:
(defun test-origin ()
"Test function"
(message "origin"))
(defalias 'defalias-copy 'test-origin
"Alias of `test-origin'")
(defalias 'symbol-function-copy
(symbol-function 'test-origin)
"Copy (in my intention) of `test-origin`")
(defun test-override ()
(message "override"))
- If I advice
test-origin
:
(advice-add 'test-origin
:override
#'test-override)
(test-origin) ; => "override"
(defalias-copy) ; => "override"
(symbol-function-copy) ; => "origin"
also defalias-copy
get adviced. (This is not good if I want override test-origin
with an adviced version of defalias-copy
later.)
- If I advice
defalias-copy
:
(advice-remove 'test-origin #'test-override)
(advice-add 'defalias-copy
:override
#'test-override)
(test-origin) ; => "origin"
(defalias-copy) ; => "override"
(symbol-function-copy) ; => "origin"
- If I advice
symbol-function-copy
(advice-remove 'defalias-copy #'test-override)
(advice-add 'symbol-function-copy
:override
#'test-override)
(test-origin) ; => "origin"
(defalias-copy) ; => "origin"
(symbol-function-copy) ; => "override"
But due to the bug mentioned above, I suspect that the combination of defalias
and symbol-function
is not the appropriate way to obtain a copy of a function that is completely independent from the original
I thought of using
symbol-function
based on this: How to copy a function?.My purpose is to advice (override) a function with an adviced copy of the same function.
re-search-forward
. The links are there just to justify my question.