How would I convert the following old style advice to a new style advice?
(setq python--pdb-breakpoint-string "import pdb; pdb.set_trace()") (defadvice compile (before ad-compile-smart activate) "Advises `compile' so it sets the argument COMINT to t if breakpoints are present in `python-mode' files" (when (derived-mode-p major-mode 'python-mode) (save-excursion (save-match-data (goto-char (point-min)) (if (re-search-forward (concat "^\\s-*" python--pdb-breakpoint-string "$") (point-max) t) ;; set COMINT argument to `t'. (ad-set-arg 1 t)))))) Snippet from: https://masteringemacs.org/article/compiling-running-scripts-emacs
From Porting old advice, the recommendations are :around or :filter-args.
Using :filter-args, I'm at a loss for what to return for the first argument of compile. The first argument is command. I have no clue what that is, or might be, and don't know how to find it during advising/let it pass through.
(advice-add 'compile :filter-args (lambda () (when (derived-mode-p major-mode 'python-mode) (save-excursion (save-match-data (goto-char (point-min)) (if (re-search-forward (concat "^\\s-*" python--pdb-breakpoint-string "$") (point-max) t) ;; new arglist: ;; (command t) )))))) Using :around, I think I have the same issue, but it's hard to tell. I'm getting overwhelmed by the documentation. It seems like I would need to call apply if the if passes and call the original compile otherwise:
(advice-add 'compile :around (lambda (oldcompile) (when (derived-mode-p major-mode 'python-mode) (save-excursion (save-match-data (goto-char (point-min)) (if (re-search-forward (concat "^\\s-*" my-python-break-string "$") (point-max) t) (apply oldcompile command t) oldcompile))))))