I always have file called ~/notes.org open in my emacs. It's my "notepad".

As a developer, I visit hundreds of files every day. Sometimes, I will be inside a file, looking at a method definition

module Email
  class SendAlertsWorker < ApplicationWorker
    include Sidekiq::Worker

    sidekiq_options unique: :until_executed

    def perform

When I'm on line 7, for example, is there some way I can tell emacs to insert/append a link to file:/whatever/file/I/was/browsing::def perform

in to my ~/notes.org

That way, if I have to revisit that particular file location later in the week, I have a convenient link to it in my org file.

  • See the manual for org-capture. – Dan Sep 9 '17 at 1:04
  • These answers use another package which requires it's own configuration and workflow. I think something that simply puts it on the kill-ring or a special buffer would be ideal and stand-alone. – salotz Jan 19 '18 at 21:27

You could use (org-store-link) (perhaps bound to [C-l]) on the line you wish to save, then call a capture template with (org-capture) (perhaps bound to [C-c c]), where the capture template you select uses "%a" to insert the link in the appropriate spot in the todo item in your notes file.

Use something like this for your capture template:

(setq org-capture-templates
      (quote (
              ("t" "todo" entry (file (lambda () (expand-file-name "~/notes.org")))
               "* TODO [#C] %?\n%a\n")

If you use library Bookmark+ then you can easily create an Org-mode link that jumps to a bookmark, which destination can be in an Org file (the same or another) or anything else (Info, Dired, any file, an image, etc.)

From section Org Mode Links that Jump To Bookmarks in the Bookmark+ doc:

You can also easily define Org-mode links that jump to bookmarks. These links are persistent. Again, the bookmark linked can be of any type.

You can use the standard Org command org-store-link (C-c l) in buffer *Bookmark List* to store a link to the bookmark at point. (This is also item Store Org Link in the mouse-3 popup menu.)

Outside buffer *Bookmark List* you can use command bmkp-store-org-link to store a link to any bookmark. You are prompted for the bookmark name. You can even enter the name of a bookmark that does not yet exist. (This is also item Store Org Link To... on menu Bookmarks.)

If you use a numeric prefix arg with either command then the bookmark link stored will be for jumping to the bookmark in the same window. Without a numeric prefix arg, the link will use another window. (Org mode defines other behaviors for non-numeric prefix args, such as C-u C-u.)

As usual, to insert a bookmark link, you use command org-insert-link. Enter the name of the target bookmark at the prompt. In Org mode you can use the usual Org key bindings to follow the link. In any mode you can use standard Org command org-open-at-point-global (not bound to a key by default).

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.