universal-ctags/citre

`citre-update-tags-file` incorrect use `read-file-name` corrupt the project file

lynnux opened this issue · 4 comments

Emacs 29.0.50, win10 64. When I open one file in project, and M-x citre-update-tags-file, it will prompt me to select the tag file, and then tip me xxx doesn't contain recipe for updating. Edit its recipe?, and I select yes, the whole file content is replaced by the tag content generate by ctags, it's a disaster!
And I find the code has bug in citre-update-tags-file : (read-file-name "Tags file: "(citre-tags-file-path)) C-x C-e at this code end, after select tag, this will get the file path of citre-ctags.el, not the tag path, cause

(read-file-name PROMPT &optional DIR DEFAULT-FILENAME MUSTMATCH
INITIAL PREDICATE)

the DIR should not be the file path. The other place use read-file-name some are right, some are wrong. I don't know whether it's a bug in Emacs 29.0.50 or not.

like this gif: 11
And I tested if correctly set DIR arg, read-file-name will work as expected.

A few thoughts:

C-x C-e at this code end, after select tag, this will get the file path of citre-ctags.el, not the tag path

I guess you did this in citre-ctags.el? This would make citre the current project.

I select yes, the whole file content is replaced by the tag content generate by ctags, it's a disaster!

Sounds like your minibuffer completion tool (ivy, selectrum, etc) made your current file the default tag file, and citre then overwrote the file.

To validate these points, I suggest:

  1. Disable your minibuffer completion package (or more aggressively start with emacs -Q and load only citre).
  2. Navigate to your project buffer.
  3. Evaluate (default keybinding is M-:):
    • (citre-tags-file-path) --> unexpected result indicates a bug in citre.
    • (read-file-name "Tags file: " (citre-tags-file-path)) --> unexpected result indicates a bug in emacs.

Hope it helps.

With emacs -Q and loaded citre, without any completion tool, in citre-update-tags-file:

  • (citre-tags-file-path) --> get correct tag path
  • (read-file-name "Tags file: " (citre-tags-file-path)) --> still get the path of citre-ctags.el, not the tag path.

But if set DIR to nil, will get corect result.
11

Thanks a lot for the report and investigation @lynnux @chen-chao ! This should be fixed, please test.

I could confirm the bug. I think this usage works well in Emacs 27 but not Emacs 28. I've recently updated to Emacs 28 and have not tagging any new project since then. Maybe that's why I haven't notice it.