1

I am using bookmark+.el in Emacs 25.1. When I press C-x r m (bound to bookmark-set) and point is on a symbol, it will be used as the default candidate for the new bookmark to be created.

I would like to change this behavior slightly, such the the current line number (as given by line-number-at-pos) is appended to the name. So for example if point is on a symbol my-test-function at line 31 in a buffer my-lisp-functions.el and I press C-x r m the default candidate should be my-test-function:31 (and not just my-test-function as is the current behavior).

After browsing the file bookmark+-1.el, I think I have to customize the variable bmkp-new-bookmark-default-names. I would like to do this from lisp code (i.e. not use the M-x customize gui).

The documentation of the variable bmkp-new-bookmark-default-names says:

The option value is a list of functions that do not require an argument and return a string (or nil). They are invoked, in order, to produce the default names.

1

Use something like this as one of the functions:

(defun foo ()
  (let* ((ff    (function-called-at-point))
         (ff    (and ff  (symbolp ff)  (symbol-name ff)))
         (line  (format "%d" (line-number-at-pos))))
    (if ff (concat ff ":" line) line))

(Could just use that as an anonymous function - don't need to name it.)

Example with only one function (that one) -- put this in your init file:

(setq bmkp-new-bookmark-default-names  (list 'foo))

If you do use Customize then just click INS and add foo (if defined) or the equivalent lambda expression; then save.

(See also Autonamed Bookmarks for examples of providing names for autonamed bookmarks, in case that is really what you want.)

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.