Skip to content
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

Incorrect cursor placement in minibuffer when prefixed #159

Open
Raphus-cucullatus opened this issue Aug 10, 2019 · 0 comments
Open

Incorrect cursor placement in minibuffer when prefixed #159

Raphus-cucullatus opened this issue Aug 10, 2019 · 0 comments

Comments

@Raphus-cucullatus
Copy link

I sometimes want to pass additional argument to ag. According to the DOCSTRING,

If called with a prefix, prompts for flags to pass to ag.

It works well when my search string contains no shell-quote characters. For example, if I use C-u M-x ag, and search "struct", command args will be prompted in the minibuffer with the point/cursor placed at the end of other args and before the "--" and wait for my input (Here I use <cursor> to indicate the cursor position):

ag command: ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats <cursor> -- struct .

However, if my search string contains shell-quote characters, the cursor is placed weirdly:

  1. if I use C-u M-x ag, and search "struct kvm":
ag command: ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats  <cursor>-- struct\ kvm .
  1. if there are more shell-quote characters, for example, search "struct kvm {":
ag command: ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats  --<cursor> struct\ kvm\ \{ .

The cursor is placed after the "--"!

If I want to add additional argument, I have to move the cursor back before "--". It seems that the cursor position in the minibuffer is incorrectly calculated.

My guess

In ag/search, the point position is calculated as follows:

ag.el/ag.el

Line 262 in bd81d68

(let ((adjusted-point (- (length command-string) (length string) 5)))

However, here command-string is quoted, while string is unquoted. So direct subtraction does not take the backslash into account. In my case, command-string is ag --literal --group ... struct\ kvm\ \{ ., while string is struct kvm {.

Subtracting by 5 is also incorrect after the introduction of the commit bd81d68 since the length after "--" can be arbitrary due to :files.

Other Information

On my machine, the output of ag --version is

ag version 2.2.0

Features:
  +jit +lzma +zlib

My Emacs version is 26.1 (Download from emacsformacosx).

I'm using: macOS Mojave 10.14.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant