-
-
Notifications
You must be signed in to change notification settings - Fork 339
counsel.el (counsel--call): Touch-up #1828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “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? Sign in to your account
Conversation
4b54a4d
to
653f0b2
Compare
counsel.el
Outdated
(with-temp-buffer | ||
(insert-file-contents stderr) | ||
(buffer-substring-no-properties | ||
(point) (line-end-position)))))))))) |
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.
point-min
?
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.
point-min
and point
are equivalent here, point
is simpler, and point-min
conveys no more intention than point
.
line-beginning-position
conveys more intention in the context of a subsequent line-end-position
, but that would be overkill.
I call the colour of this bikeshed point
.
Use process-file instead of call-process. Add docstring. Avoid multi-line error message by returning only the first line of stderr. Deconstruct error information as file-error data for easier access. Guard stderr file access with file-{exists,readable}-p just in case. Re: abo-abo#1827
653f0b2
to
40f7d58
Compare
What's the reason for using only the first line of the error message? I think if an error happens, we should get all the info we can get to debug it. |
There's a subtle difference between error messages and error data. Error messages are inherently user-visible, and by convention comprise a single line that doesn't hog too much real-estate in the minibuffer and My initial thought was to try to fit the error message on a single line, hence only including the first line of
Sure. It's just my knee-jerk reaction was that including verbose, multiline file contents in an Elisp error felt a bit awkward/non-idiomatic. So I propose three compromises:
I wouldn't mind (1) or (2), but I kind of prefer (3) for its flexibility and losslessness (I don't think warnings buffers are automatically truncated like |
I think you can simply offer |
That's exactly how the built-in warning system works, which is why I'd like to reuse it; see |
counsel.el (counsel--git-grep-count-func-default): Simplify.
Bring back the previous behaviour[1] of returning the entire contents of stderr, but this time put them in a warning, rather than in the error data itself. [1]: counsel.el (counsel--call): Add wrapper around call-process 2018-11-28 11:07:54 +0100 9862640 Re: abo-abo#1828
I have pushed a couple more commits to help illustrate my point, but will revert them if you disagree with the warning approach. |
(let ((git-dir (counsel--call "git" "rev-parse" "--git-dir"))) | ||
(read (counsel--call "du" "-s" git-dir))) | ||
(error 0)))) | ||
(or (unless (eq system-type 'windows-nt) |
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.
Why Windows is excluded? MSYS2 has coreutils package and also available as standalone from gnuwin32. I think you better let it fail simply which would be consistent on either Unix or Windows if du
is not available (what makes you think that there could not be a situation on Unix when du
is not available?).
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.
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.
On Windows it's possible for the user to use https://git-scm.com/download/win, with no du
available on the system. Plus process calls are a lot more expensive on Windows than on Linux. So I decided to go with piping the whole git tree into Emacs and do elisp filtering, rather than start a new process on each key press. Of course it will work poorly with a repo that has over 20k lines; it's a trade-off.
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.
Did you profile your statement about slow process calling on Windows? I believe that decision is not worth the hassle that it creates, namely platform support asymmetry and, as a result, convoluted implementation and additional maintenance. Most of those who use Emacs under Windows, will have either MSYS2 or Cygwin, which both provide du
. If du
is not there, then the call will simply fail and you can still fallback to your filtering algorithm. Otherwise, I see no reason to cut off Windows power users like this. As you admitted, your custom filtering will not perform well on large repos anyways and 20K is nothing by the way.
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.
Furthermore, may I ask why do you have to call du
on each key press?
(let ((git-dir (counsel--call "git" "rev-parse" "--git-dir"))) | ||
(read (counsel--call "du" "-s" git-dir))) | ||
(error 0)))) | ||
(or (unless (eq system-type 'windows-nt) |
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.
Line 1214 in 9862640
"Store the line count in current repository.") |
It's size in bytes, not line count isn't it? Perhaps change the documentation and rename it to ...-size
instead to convey the intent in more standard way?
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.
See my unanswered questions in #1827. I find the naming, documentation, and implementation of these features confusing, but I'm not sure how to proceed in changing them. Perhaps @abo-abo can advise.
Don't forget, though, that all of this counting is merely intended as a proxy, not as a hard and fast metric.
counsel.el
Outdated
(setq res (list 'file-error | ||
(mapconcat #'identity `(,@command "failed") " ") | ||
res)) | ||
(lwarn 'ivy :warning "%s" |
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 think it's an :error
(it already failed and we raise
).
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 process indeed encountered an error, but that doesn' necessarily translate as an error with Ivy. I'm not disagreeing with you, I'm just playing devil's advocate. I'd be happy with any one of :debug
, :warning
, or :error
. The only thing I'm concerned about is that, the higher the severity, the higher the chance of annoying users, e.g. with false positives.
Here's the description of the different severity levels, for posterity:
‘:emergency’
A problem that will seriously impair Emacs operation soon if you do
not attend to it promptly.
‘:error’
A report of data or circumstances that are inherently wrong.
‘:warning’
A report of data or circumstances that are not inherently wrong,
but raise suspicion of a possible problem.
‘:debug’
A report of information that may be useful if you are debugging.
I'll let someone else decide.
delete-file does not signal an error when given a non-existent file, and guarding insert-file-contents is at best unnecessary and at worst a race condition. Re: abo-abo#1828
5dd66d5
to
b67b3be
Compare
Bring back the previous behaviour[1] of returning the entire contents of stderr, but this time put them in a warning, rather than in the error data itself. Also remove racey file-{readable,exists}-p guards for the stderr file. delete-file is able to handle non-existent files, and any errors that insert-file-contents encounters can be used in place of the stderr contents. [1]: counsel.el (counsel--call): Add wrapper around call-process 2018-11-28 11:07:54 +0100 9862640 Re: abo-abo#1828
b67b3be
to
fb126fb
Compare
Bring back the previous behaviour[1] of returning the entire contents of stderr, but this time put them in a warning, rather than in the error data itself. Also remove racey file-{readable,exists}-p guards for the stderr file. delete-file is able to handle non-existent files, and any errors that insert-file-contents encounters can be used in place of the stderr contents. [1]: counsel.el (counsel--call): Add wrapper around call-process 2018-11-28 11:07:54 +0100 9862640 Re: abo-abo#1828
Bring back the previous behaviour[1] of returning the entire contents of stderr, but this time put them in a warning, rather than in the error data itself. Also remove racey file-{readable,exists}-p guards for the stderr file. delete-file is able to handle non-existent files, and any errors that insert-file-contents encounters can be used in place of the stderr contents. Also fix off-by-one error when returning empty output from a successful command. [1]: counsel.el (counsel--call): Add wrapper around call-process 2018-11-28 11:07:54 +0100 9862640 Re: abo-abo#1828
fb126fb
to
33d8e96
Compare
Thanks. |
GJ, looks solid. |
process-file
instead ofcall-process
.file-error
data for easier access.file-{exists,readable}-p
just in case.Re: #1827