0

I have this code:

(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 'search-forward-ifpmod
  (symbol-function 'search-forward)
  "Copy of `search-forward' function (to be) adviced to obey to
`isearch-filter-predicate'")

(advice-add 'search-forward-ifpmod
            :around
            #'make-search-sensitive-to-ifpmod-advice)

(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)

;; The following breaks my minor-modes definitions
(advice-add 're-search-forward-ifpmod
            :around
            #'make-search-sensitive-to-ifpmod-advice)

I found that this particular code snippet:

(advice-add 're-search-forward-ifpmod
            :around
            #'make-search-sensitive-to-ifpmod-advice)

breaks my minor-modes definitions. E.g. if I evaluate the code above and later on the following code (MWE):

(defun mwe-function-1 ()
  "MWE function 1"
  (interactive)
    (message "function 1 executed"))

(define-minor-mode mwe-mode
  "MWE mode"
  :init-value nil
  :lighter (:eval (propertize " MWE "
                              'face '(:foreground
                                      "RoyalBlue"
                                      :background
                                      "DarkGoldenrod1")))

  :keymap
  `(
    (,(kbd "<C-kp-1>") . mwe-function)
    )

  (if mwe-mode
      (easy-menu-define mwe-menu mwe-mode-map
        "MWE"
        '("MWE mode"
          ;; I want the menu on mode-line only:
          :visible (not (eq (framep (selected-frame)) 'x))
          ["mwe-function-1" mwe-function-1
           :help "mwe-function 1"]
          ))
    t))

I get this error:

internal-macroexpand-for-load: Eager macro-expansion failure: (wrong-type-argument integer-or-marker-p nil)

Step to reproduce the error:

  1. emacs -Q
  2. Evalute the add-advice code
  3. Evalute my minor-mode definiton

Did I make a mistake in the add-advice usage or is it a bug?

Edit. Added backtrace and my Emacs version:

  • Backtrace

Debugger entered--Lisp error: (error "Eager macro-expansion failure: (wrong-type-argumen...") error("Eager macro-expansion failure: %S" (wrong-type-argument integer-or-marker-p nil))
internal-macroexpand-for-load((define-minor-mode mwe-mode "MWE mode" :init-value nil :lighter (:eval (propertize " MWE " 'face '(:foreground "RoyalBlue" :background "DarkGoldenrod1"))) :keymap `((,(kbd "") . mwe-function)) (if mwe-mode (easy-menu-define mwe-menu mwe-mode-map "MWE" '("MWE mode" :visible (not (eq ... ...)) ["mwe-function-1" mwe-function-1 :help "mwe-function 1"])) t)) nil)
eval-buffer() ; Reading at buffer position 767
funcall-interactively(eval-buffer) command-execute(eval-buffer record) execute-extended-command(nil "eval-buffer" "eval-bu")
funcall-interactively(execute-extended-command nil "eval-buffer" "eval-bu") command-execute(execute-extended-command)

  • Emacs version
emacs -version
GNU Emacs 29.2
Development version ac89b1141a26 on master branch; build date 2024-02-27.
2
  • FIrst step as always: make sure that debug-on-error is t and redo the problematic operation. You should now get a backtrace which you should add to your question.
    – NickD
    Commented Mar 6 at 5:08
  • @NickD added the backtrace. Thanks.
    – Gabriele
    Commented Mar 6 at 5:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.