Giter Club home page Giter Club logo

Comments (5)

jacktasia avatar jacktasia commented on July 4, 2024

It's necessary because ag/grep search saved files. If you've changed a file a lot and try to jump then you could very well jump to an old position, which is extremely confusing and makes dumb-jump seem broken.

from dumb-jump.

nickdrozd avatar nickdrozd commented on July 4, 2024

@jacktasia I spent several minutes yesterday thinking dumb-jump was busted because it kept dropping me off four or five lines above the functions I was searching for. Then I realized the file wasn't saved, and I thought "That's stupid, why doesn't it prompt to save before searching?" Then I came here and discovered that someone else had the exact opposite complaint ("This sucks, why does it keep prompting me to save?").

You can't please everyone I guess.

Or can you? Maybe there could be a prompt-before-searching flag? Is there one already? I don't know anything about the history of this issue. Was the prompt dropped at some point? If so, could you point me to the commit? I would be happy to add a customizable option if you think it would useful.

It's a great package, btw. Aside from this very minor problem, it really does "just work".

from dumb-jump.

jacktasia avatar jacktasia commented on July 4, 2024

@nickdrozd Are you on an old version? It should be warning you when you jump to an unsaved buffer, but maybe there's a bug in some case. I know I see this prompt pretty often, but if you know of a case where this failing I'd love to hear about it. For the record, here's the PR/commit where this changed: #141

It's a great package, btw. Aside from this very minor problem, it really does "just work".

Thanks! I appreciate the kind words.

from dumb-jump.

nickdrozd avatar nickdrozd commented on July 4, 2024

@jacktasia This problem is on master. I took a look and I think I understand what is happening.

The function that checks for modifications is

(defun dumb-jump-file-modified-p (path)
  "Check if PATH is currently open in Emacs and has a modified buffer."
  (let ((modified-file-buffers
         (--filter
          (and (buffer-modified-p it)
               (buffer-file-name it)
               (file-exists-p (buffer-file-name it)))
          (buffer-list))))
    (member path (--map (buffer-file-name it) modified-file-buffers))))

Now, when I test this code manually, it works fine as long as I pass
in full file paths. But it doesn't get full paths, just the filename
(dumb-jump.el, rather than /path/to/dumb-jump.el).

Why is the short filename getting passed in? The actual command that
does the searching (git grep for me) is executed in
dumb-jump-run-command. It takes an argument cur-file, and what
gets passed in is a full path.

(defun dumb-jump-run-command
    (look-for proj regexes lang exclude-args cur-file line-num parse-fn generate-fn)
  "Run the grep command based on the needle LOOK-FOR in the directory TOSEARCH"
  (let* ((proj-root (if (file-remote-p proj)
                        (directory-file-name
                         (tramp-file-name-localname (tramp-dissect-file-name proj)))
                      proj))
         (cmd (funcall generate-fn look-for cur-file proj-root regexes lang exclude-args))
         (shell-command-switch (dumb-jump-shell-command-switch))
         (rawresults (shell-command-to-string cmd)))

    (message "cur-file -- %s" cur-file)  ;; <-- full path
    (message "cmd -- %s" cmd)  ;; <-- git grep
    (when dumb-jump-debug
      (dumb-jump-message
       "-----\nDUMB JUMP DEBUG `dumb-jump-run-command` START\n----- \n\ncmd: \n\t%s\n\nraw results: \n\n\t%s \n\n-----\nDUMB JUMP DEBUG `dumb-jump-run-command` END\n-----\n" cmd rawresults))
    (when (and (s-blank? rawresults) dumb-jump-fallback-search)
      (setq regexes (list dumb-jump-fallback-regex))
      (setq cmd (funcall generate-fn look-for cur-file proj-root regexes lang exclude-args))
      (setq rawresults (shell-command-to-string cmd))
      (when dumb-jump-debug
        (dumb-jump-message
       "-----\nDUMB JUMP DEBUG `dumb-jump-run-command` (FALLBACK!) START\n----- \n\ncmd: \n\t%s\n\nraw results: \n\t%s \n\n-----\nDUMB JUMP DEBUG `dumb-jump-run-command` (FALLBACK) END\n-----\n" cmd rawresults)))
    (unless (s-blank? cmd)
      (let ((results (funcall parse-fn rawresults cur-file line-num)))
        (message "run-command -- results: %s" results)  ;; <-- short filename
        (--filter (s-contains? look-for (plist-get it :context)) results)))))

The results object there at the end of the function contains
filenames rather than full paths. This is apparently the result the
result of a the grep search:

dumb-jump.el:1528:                   (dumb-jump-read-config proj-root proj-config)))
dumb-jump.el:1579:                   (dumb-jump-read-config proj-root proj-config)))

So I guess the search command needs to be modified. How, I don't know,
and a quick google search turned up nothing.

from dumb-jump.

jacktasia avatar jacktasia commented on July 4, 2024

@nickdrozd Thanks for the analysis! This appears to be an issue when using git-grep. I could reproduce it with git-grep but not when forcing ag (which is what I do by default). #200 fixes it for me. If you have a chance please confirm. Thanks!

from dumb-jump.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.