The option org-return-follows-link is wonderfully convenient except when the point is at the end of the line where the intention is usually to insert a carriage return.

What's the best way to change this behavior to insert a carriage return in this edge case?

3 Answers 3


I made the following modification to org-return. I'll change the correct answer if a better one is offered.

  ((and org-return-follows-link
+   (not (eolp))
    (or (org-at-timestamp-p t)
        (org-at-date-range-p t)
       (org-in-regexp org-any-link-re)))
  • 1
    You might want to use eolp instead of comparing point manually: gnu.org/software/emacs/manual/html_node/elisp/Near-Point.html . Also, this would be a great contribution to org-mode.
    – zck
    Nov 27, 2015 at 3:53
  • Thanks for mentioning oelp. It's definitely the behavior I want, but technically the point is within the link pattern. Some people might consider it sloppy behavior :-\
    – ebpa
    Nov 27, 2015 at 4:00
  • At least bring it up. It might be a nice preference to set, if it's not the default.
    – zck
    Nov 27, 2015 at 4:41
  • It doesn't just happen within/after [[org][links]] - if you paste a url into a blank line and hit return, the link is followed. Thanks for this solution. Using Org-mode 8.3.3-2-g6bc48c-elpa.
    – Bill White
    Jan 11, 2016 at 23:45

I would prefer this, as it simply disables follow-link:

;point at eol should not follow link
(defun my/org-return ()
  "disable org-return-follows-link if at bol or eol"
  (let* ((follow org-return-follows-link)
         (org-return-follows-link (and follow (not (or (bolp) (eolp))))))
(define-key org-mode-map (kbd "<return>") 'my/org-return)

Also, I just noticed that what I really want is this:

;C-m should always just edit text
(define-key org-mode-map (kbd "C-m") 'newline-and-indent)

my soluton for history purpose. Patch for original code not needed.

   (defun bss/my-org-return ()
     "Insert newline if we at beginng or end of line"
     (if (or (eolp) (bolp))
   (define-key org-mode-map (kbd "<return>") 'bss/my-org-return)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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