0

I am using bookmark+ and helm mode.

Debugging a large Fortran code base, I have created some bookmarks that has the same name as some of the Fortran subroutines. Now, I would like to put the cursor on the subroutine name and press C-x r b to run bookmark-jump to the given function (given at point). As it works now, a Helm buffer with name "bookmark-jump" is shown, and the minibuffer prompt is shown as "Jump to bookmark:".

I would like to have the thing-at-point filled in as initial input after the minibuffer prompt. How can this be done?

Note: I have looked at the bookmark+-1.el source code and found a variable bmkp-default-bookmark-name, but that does not allow the initial input to be set as far as I can see.

  • Define "initial input" in your context. bmkp-default-bookmark-name is used in bookmark-jump as the DEFAULT argument to completing-read. If you use bookmark-jump interactively then just use M-n to retrieve the default value. But if you use something (e.g., Helm) other than bookmark-jump (interactively) then check with what that other thing does - whether and how it uses the default value. – Drew Jun 11 '17 at 17:04
  • 1
    Googling a bit (not much) shows helm-sources-using-default-as-input and helm-maybe-use-default-as-input. Maybe one of those, or some other Helm setting, can help you. Or maybe a Helm users will provide a simple answer of how to get Helm to insert the default value as the initial input. – Drew Jun 11 '17 at 17:12
  • (If you were using Icicles, you would need only to customize (or bind locally) option icicle-default-value, to get the default value inserted as initial input. In fact, 4 of the 6 possible values for that option cause such insertion.) – Drew Jun 11 '17 at 17:16
0

The magic happens in (interactive):

(defun say-word (word)
  (interactive (list
                (read-string (format "word (%s): " (thing-at-point 'word))
                             nil nil (thing-at-point 'word))))
  (message "The word is %s" word))

This will set the word under point as default input.

I got it from here:

Link to Question with Answer

  • Thanks this looks interesting. Actually my bookmark name also contains the Fortran file name that the subroutine is in. So for example, if the cursor is located at the string setup in (buffer) file init.f95 and the subroutine setup is defined in file start.f95, the bookmark name will be setup:start.f95. // Also, I would like to know how to bring up the helm buffer with the initial input set to setup. If I call bookmark-jump directly with "setup:start.f95" as an argument, the Helm buffer is not shown at all. – Håkon Hægland Jun 11 '17 at 7:50
  • You could assemble your bookmark name (replace the last line by this): (message "The is %s" (concat word ":" (buffer-name)))). By this way you could also redefine the (interactive) default. But I cannot help you with Helm or bookmark-jump, sorry. – jue Jun 11 '17 at 8:22
  • No problem :) Also note that buffer-name in your last comment will be init.f95 and not start.f95, so that would not work. – Håkon Hægland Jun 11 '17 at 9:21
0

I found a possible workaround by advicing helm--completing-read-default:

(advice-add 'helm--completing-read-default
            :around
            #'my-set-initial-helm-completing-read-input-as-thing-at-point)

(defun my-set-initial-helm-completing-read-input-as-thing-at-point
    (helm-completion-function
     prompt collection
     &optional
     predicate require-match
     orig-initial-input hist def
     inherit-input-method)
  (let ((initial-input orig-initial-input))
    (when (string= prompt "Jump to bookmark: ")
      (setq initial-input (thing-at-point 'symbol t)))
    (apply helm-completion-function
           prompt collection
           predicate require-match
           initial-input hist def
           inherit-input-method)))

Edit:

In case I would like to jump to a bookmark which name is not given at point, I created a special function my-thing-at-point-bookmark-jump which I bound to C-x j j. Then I can use C-x r b as the normal bookmark-jump:

(define-key ctl-x-map "j" bmkp-jump-map)
(define-key bmkp-jump-map "j" #'my-thing-at-point-bookmark-jump)
(defvar my-thing-at-point-bookmark-jump nil
  "Whether to insert thing at point as initial input into Helm completion buffer.")
(defun my-thing-at-point-bookmark-jump()
  (interactive)
  (let ((my-thing-at-point-bookmark-jump t))
    (call-interactively 'bookmark-jump)))

Finally, change this part in the advicing function my-set-initial-helm-completing-read-input-as-thing-at-point defined above:

(when (string= prompt "Jump to bookmark: ")
  (when my-thing-at-point-bookmark-jump
    (setq initial-input (thing-at-point 'symbol t))))
  • This sounds like something general, for Helm. Is there no general Helm way to tell Helm to insert the default value for completion, so that you don't have to do what you are doing in N specific cases? – Drew Jun 11 '17 at 17:06

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.