3

At work, I very commonly have to look up bits of information about strings in my code. For instance, we might use an incomprehensible ID, "a587fg", to refer to a customer with a perfectly comprehensible name, "FooCorp". It's fairly easy to define a function and bind it to a key mapping to look up a thing under point -- but what I'd much prefer is an ElDoc-style "here's some info about thing-under-point in the echo area, automatically" situation.

My reflex was to go to ElDoc itself, but I can't get it to work and I've no idea why. My best theory so far is that ElDoc only triggers on symbols -- which, of course, an arbitrary string isn't, and probably shouldn't be.

So: maybe I'm wiring up ElDoc wrong? Maybe there's a better way to do info-of-string-at-point? Who can help me understand how to get this working?

For reference, here's how I'm wiring things up:

(defun my-eldoc-function ()
  "Get info about string at point"
  (let (the-str)
    (if (setq the-str (thing-at-point 'string t))
        (my-str-doc-fun the-str) ;; Returns a string or nil
      nil)))

(set (make-local-variable 'eldoc-documentation-function)
     'my-eldoc-function)
  • Perhaps a minor mode that does the echoing as the cursor moves around -- is that what you were thinking? – Emacs User Dec 3 '15 at 18:57
  • Yep -- that's precisely what I have in mind. I've already defined the minor mode, and have this lookup done as a function triggered by a key command; now I want to be able to lookup a value just by putting point on it. – Gastove Dec 3 '15 at 19:29
2

It is not very clear to me what's the string that you wanted, and thing-at-point doesn't understand either. The following displays corresponding commit summary if point is at hash 36dbe6f (see eldoc-documentation-function's docstring to learn how to change it, your way seems not correct).

(defun foo-eldoc-documentation-function ()
  (let ((str (thing-at-point 'word)))
    (when (string= "36dbe6f" str)
      "* 36dbe6f More emacs-module.c fixes for wide ints")))

(add-function :before-until (local 'eldoc-documentation-function)
                #'foo-eldoc-documentation-function)
  • Oh huh. I may have fallen prey to emacswiki again -- it provides a completely different example than you do. I'll try your approach and check out the doc string and report back. – Gastove Dec 3 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.