This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-02
Channels
- # announcements (1)
- # babashka (4)
- # beginners (39)
- # calva (36)
- # cherry (11)
- # cider (23)
- # clj-on-windows (3)
- # clojure (105)
- # clojure-brasil (1)
- # clojure-chicago (3)
- # clojure-conj (8)
- # clojure-denver (4)
- # clojure-europe (18)
- # clojure-germany (5)
- # clojure-hungary (13)
- # clojure-nl (1)
- # clojure-norway (31)
- # clojure-sweden (9)
- # clojure-uk (2)
- # clojurescript (22)
- # core-async (4)
- # cursive (8)
- # data-science (25)
- # datomic (14)
- # devops (1)
- # emacs (9)
- # events (5)
- # holy-lambda (32)
- # hyperfiddle (26)
- # introduce-yourself (2)
- # kaocha (1)
- # leiningen (11)
- # lsp (17)
- # malli (8)
- # off-topic (84)
- # pedestal (4)
- # polylith (2)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (8)
- # sql (4)
- # tools-deps (8)
- # transit (5)
- # vim (1)
- # vscode (1)
- # xtdb (45)
Is there some gotcha to advising fns that take prefix args? e.g. If I have this:
(defun sw1nn/cider-portal-clear (&optional clear-repl)
"Clear CIDER portal."
(interactive)
(if (sw1nn/portal-enabled-p)
(cider-nrepl-sync-request:eval "(portal.api/clear)")
(message "portal not enabled")))
(advice-add 'cider-repl-clear-output :before #'sw1nn/cider-portal-clear)
C-c C-o
is bound to cider-repl-clear-output
. When I make those keystrokes it clears the repl output as expected and calls my cider-portal-clear
fn. This is good.
cider-repl-clear-output
optionally takes a prefix arg. Without the advice installed when I call it with C-u C-c C-o
it clears the whole buffer (actually it calls cider-repl-clear-buffer
). This is also good.
However, with the :before
advice installed, when I call it with C-u C-c C-o
it clears the repl output, not the whole buffer as expected. It still calls the cider-portal-clear
fn. This is incorrect behaviour AFAICT.
Note that if I use an :around
advice, everything works as expected.
;; works with C-c C-o binding and C-u C-c C-o binding
(advice-add 'cider-repl-clear-output :around (lambda (orig &rest args)
(apply orig args) (sw1nn/cider-portal-clear args)))
I think the 'gotcha' is that the advice (interactive)
declaration has to match the function being advised. Initially I didn't have the clear-repl
arg in my advice (since I don't use it there). Turns out that by changing to (interactive "P")
in the advice (which then matches the cider-repl-clear-output
interactive
declaration everything then works as expected. There is a mention that interactive
isn't really a function call in the doc, but the exact behaviour in the case of conflicts doesn't seem to be specified anywhere
When i try to do any of my interactive helm commands i get this error.
helm-M-x-execute-command: Wrong type argument: commandp, cider-connect-clj\ \ [2 times]
What would i do to fix this?
I feel like this command (cider-connect-clj) worked like half an hour ago, and since then, I haven't done anything. a quick google shows that this can be caused if the fn in question (cider-connect-clj) is lacking the call to the emacs interactive function... but that can't be it, because it's defiantly there.
As an aside, the documentation for commandp reads like it was written by someone who already knew what it did:
Non-nil if FUNCTION makes provisions for interactive calling.
This means it contains a description for how to read arguments to give it.
The value is nil for an invalid function or a symbol with no function
definition.
...
Not 100% sure how autoload works but is cider not loaded? The symbol cider-connect-clj
certainly is commandp
.
A function is de facto a command when it has an interactive form, like cider-connect-clj
does.
Cider should have been loaded, and it was happening for like all commands. I just restarted everything.
the emacs function helm-M-x-execute-command
is getting passed a command that seems to have characters added to the end that cause an error. I call SPC SPC (from spacemacs) which triggers the function and printed the argument and i got "eww \ \" when i expected just "eww".
and helm-M-x-execute is called from spacemacs/helm-M-x-fuzzy-matching