-
-
Notifications
You must be signed in to change notification settings - Fork 44
Add inf-clojure-prompt-on-commands and closes #48 #51
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
Conversation
02b6200
to
adafc09
Compare
Actually this does not make proper sense in terms of usability, |
On second though I would probably always prompt for |
Yeah, appropos shouldn't operate at all on this symbol at point. Guess we should emulate the cider behaviour for it.
Yeah, it'd be best to add prefix arg support for all commands can prompt or not. |
You'll have to rebase this, btw. |
Don't know how you understood the latter msg, it looks like my fingers did not want to write some words 😀 |
Is |
This command can probably be removed. It was added before the mode had |
Ok I will remove it |
b4c8f96
to
ea0c5d1
Compare
inf-clojure.el
Outdated
(interactive (inf-clojure-symprompt "Var doc" (inf-clojure-var-at-pt))) | ||
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-doc-form) var))) | ||
(interactive "P") | ||
(let ((var (if (inf-clojure--should-prompt-on-commands var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me you're not using your helper function correctly. I assume it was intended to be used with some prefix argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on this? It is working fine here, prompting when the function returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still valid, sorry for the mess 😉
inf-clojure.el
Outdated
:package-version '(inf-clojure . "2.0.0") | ||
:safe 'booleanp) | ||
|
||
(defun inf-clojure--should-prompt-on-commands (&optional invert) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prompt-on-commands-p
inf-clojure.el
Outdated
@@ -238,11 +238,17 @@ This should usually be a combination of `inf-clojure-prompt' and | |||
`inf-clojure-subprompt'." | |||
:type 'regexp) | |||
|
|||
(defcustom inf-clojure-prompt-on-set-ns t | |||
(defcustom inf-clojure-prompt-on-commands t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bit vague. Maybe "prompt-for-symbol-at-point" or something. And you forgot to update the docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new name would require to flip the logic and rename also the other functions...also maybe in the future not all the commands will take symbol at point so I was wondering if we could leave it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"like this" meaning what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning inf-clojure-prompt-on-commands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can live with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let me know if this requires more work
ea0c5d1
to
5250f74
Compare
inf-clojure.el
Outdated
"Send a command to the inferior Clojure to give source for VAR. | ||
See variable `inf-clojure-var-source-command'." | ||
(interactive "P") | ||
(let ((var (if (inf-clojure--prompt-on-commands-p var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add the prefix argument to the function signature and pass it here, instead of var
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that just a name (symbol) binding? Btw there is the same thing in cider
. I mean, it is working this way, maybe there is a better way I am not getting...Can you show me a simple piece of code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cider uses the magic current-prefix-arg
variable for this.
(defun cider--find-dwim-interactive (prompt)
"Get interactive arguments for jump-to functions using PROMPT as needed."
(if (cider--prompt-for-symbol-p current-prefix-arg)
(list
(cider-read-from-minibuffer prompt (thing-at-point 'filename)))
(list (or (thing-at-point 'filename) "")))) ; No prompt.
(defun cider--invert-prefix-arg (arg)
"Invert the effect of prefix value ARG on `cider-prompt-for-symbol'.
This function preserves the `other-window' meaning of ARG."
(let ((narg (prefix-numeric-value arg)))
(pcase narg
(16 -1) ; empty empty -> -
(-1 16) ; - -> empty empty
(4 nil) ; empty -> no-prefix
(_ 4)))) ; no-prefix -> empty
(defun cider--prefix-invert-prompt-p (arg)
"Test prefix value ARG for its effect on `cider-prompt-for-symbol`."
(let ((narg (prefix-numeric-value arg)))
(pcase narg
(16 t) ; empty empty
(4 t) ; empty
(_ nil))))
(defun cider--prompt-for-symbol-p (&optional prefix)
"Check if cider should prompt for symbol.
Tests againsts PREFIX and the value of `cider-prompt-for-symbol'.
Invert meaning of `cider-prompt-for-symbol' if PREFIX indicates it should be."
(if (cider--prefix-invert-prompt-p prefix)
(not cider-prompt-for-symbol) cider-prompt-for-symbol))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, for consistency you can use the same defcustom name - inf-clojure-prompt-for-symbol
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing - by moving out the var init from interactive
you're going to break those functions when invoked without parameters. I'm guessing you didn't really test this code. :-) You'll have to make params like var
optional and prompt for them only when they are not passed explicitly (or remove them completely).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will paste a gif showing it OK? If I hadn't tested it I would not even have opened a PR 😀 maybe I did not test some case, but all the interactive calls are working fine this way. Do you mean a call with no params from ielm
or call with no params on M-x
. The latter works but I will confirm it again today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, here is the excerpt I copied from cider: https://github.com/clojure-emacs/cider/blob/1ce1d9998fc756d3dbbb491cc6f4f0c4c397b450/cider-doc.el#L208
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read carefully the code you copied - arg
there is the prefix arg, not the the symbol at point (like in your case). I guess what you did works because when you removed the var
related code from interactive
there are two bindings for var
within the code, but this is definitely wrong. If you want to do it this way you should rename var to prompt-for-symbl
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am used to Clojure were you cannot have two bindings at the same time, the first var symbol is bound to the arg, the second is in the let scope and is bound to the result of the function call. In Clojure you take advantage of this in order to override and replace the value in input with the one you calculate and want to use in the scope of the let.
I don't know emacs' guts enough to know its different semantics about var binding and it might be confusing so I think I am going to rename it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to bother on this again, I am reading this and I really don't see any difference with Clojure and no reason why the above is wrong:
A variable can have more than one local binding at a time (e.g., if there are nested let forms that bind the variable). The current binding is the local binding that is actually in effect. It determines the value returned by evaluating the variable symbol, and it is the binding acted on by setq.
Again, you ae the boss so I will rename it 😀
inf-clojure.el
Outdated
(interactive (inf-clojure-symprompt "Var doc" (inf-clojure-var-at-pt))) | ||
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-doc-form) var))) | ||
(interactive "P") | ||
(let ((var (if (inf-clojure--prompt-on-commands-p var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're killing me, buddy. :-) var
is a prefix arg at this point, but after the if
returns it's overridden - it becomes the symbol at point. I assumed this was apparent. I find this extremely confusing, so I'd change the parameter name to something else, the let
-binding is fine. Hopefully, I managed to make myself clear this time around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry bro, I am learning right? 😀 Yeah no it was clear, I am going to change that and also use the more robust invert you posted from cider above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
5250f74
to
518488c
Compare
Ok done, waiting for you further remarks. |
Btw, I meant you should change the parameter names to something |
inf-clojure.el
Outdated
:package-version '(inf-clojure . "2.0.0") | ||
:safe 'booleanp) | ||
|
||
(defun inf-clojure--prompt-on-commands-p (&optional arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't copying this an overkill? It was needed in CIDER, because some commands had prefix arguments of their own, but here it seems pointless to make it this complex.
Frankly I wonder if we even need this defcustom
we can make all the commands not prompt by default and to prompt with a prefix argument (or when there's nothing at point). It would be simple and would get the job done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on this! I will revert back to the previous version and abolish the defcustom.
082c076
to
c0eb05e
Compare
inf-clojure.el
Outdated
|
||
(defun inf-clojure-show-var-source (prompt-for-symbol) | ||
"Send a command to the inferior Clojure to give source for VAR. | ||
See variable `inf-clojure-var-source-form', with non-nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use a separate sentence for the prefix arg everywhere.
When invoked with a prefix argument prompt-for-symbol
....
The patch makes so that the REPL commands don't prompt for things anymore (except for `inf-clojure-apropos`). For prompting, the user will need to pass a prefix argument to the command.
c0eb05e
to
ee78b65
Compare
The patch introduces a way to globally disable prompting. It deletes
inf-clojure-prompt-when-set-ns
.M-x checkdoc
warnings