0

I've noticed that placing (setq org-return-follows-link t) in your init.el has no effect on links created by org-wikinodes.el. When you hit (or RET), it just cuts the link in half...

One point to clarify though, I made a slight modification in order to org-wikinodes.el to fix a bug that was preventing links from fontifying (see my answer to this question). So it's entirely possible that I missed something...

Ideas?

  • I don't use wikinodes, but it would probably be a similar solution as one of your previous questions -- i.e., add a new condition to org-return that looks for the face property of your link that is getting cut in half. To see what properties are present, place your cursor on the link and type: C-u C-x = For example, one of your previous questions needed a new condition for the org-footnote face and if it was found, then we called org-footnote-action. In summary, you probably need a new condition that looks for the face and calls whatever action you want if the condition is met. – lawlist Jun 1 '17 at 0:36
  • Aha! I was hoping that @lawlist would join in! :D Okay, I placed the cursor on an org-wikinodes link and ran C- C-x =. These are the properties: face = org-link, fontified = t, help-echo = "Wiki Link", keymap = [Show], mouse-face = highlight. – Adam Jun 1 '17 at 10:16
  • org-return has built-in support for the org-link face that should trigger org-open-at-point. You indicate that a keymap is present which could trump/supercede org-return if it has been set with a value for the return key. Inasmuch as it should work out-out-of the box, your next step is to do a M-x describe-key on the Wiki Link and hit the return key and see if you are actually calling org-return which is the default behavior in org-mode. – lawlist Jun 1 '17 at 16:30
  • Okay, M-x describe key [RET] with point on a wikinodes link yields: RET (translated from <return>) runs the command org-return (found in org-mode-map), which is an interactive compiled Lisp function in ‘org.el’... – Adam Jun 1 '17 at 17:24
  • It sounds like everything should just work. Try with emacs -q and just the org-wikinodes.el library with (setq org-return-follows-link t) – lawlist Jun 1 '17 at 18:46
0

Okay, I have a solution. First, special thanks to Nicolas Goaziou for fixing a bug in org-wikinodes so that CamelCase links will now font-lock under Org-Mode 9.0.7. And a very special thanks to @lawlist for brainstorming this (endless) and showing me how to override org-return.

You'll need to update org-mode to get Nicolas' fix. Navigate to your ~/.emacs.d directory and run

git clone git://orgmode.org/org-mode.git
cd org-mode
make autoloads

Then open your init.el file and add the code to activate org-return-follows-link and the org-wikinodes module:

(setq org-return-follows-link t)
(custom-set-variables
 '(org-modules (quote (org-wikinodes)))
 '(org-return-follows-link t)))

Finally, add this code to override org-return:

;;; Override org-return
;;; Adds org-wikinode links to work with org-return-follows-link
(with-eval-after-load "org-wikinodes"
(defun org-return (&optional indent)
  "Goto next table row or insert a newline.

Calls `org-table-next-row' or `newline', depending on context.

When optional INDENT argument is non-nil, call
`newline-and-indent' instead of `newline'.

When `org-return-follows-link' is non-nil and point is on
a timestamp or a link, call `org-open-at-point'.  However, it
will not happen if point is in a table or on a \"dead\"
object (e.g., within a comment).  In these case, you need to use
`org-open-at-point' directly."
  (interactive)
  (let ((context (if org-return-follows-link (org-element-context)
                   (org-element-at-point))))
    (cond
     ;; In a table, call `org-table-next-row'.
     ((or (and (eq (org-element-type context) 'table)
               (>= (point) (org-element-property :contents-begin context))
               (< (point) (org-element-property :contents-end context)))
          (org-element-lineage context '(table-row table-cell) t))
      (org-table-justify-field-maybe)
      (call-interactively #'org-table-next-row))
     ;; On a link or a timestamp, call `org-open-at-point' if
     ;; `org-return-follows-link' allows it.  Tolerate fuzzy
     ;; locations, e.g., in a comment, as `org-open-at-point'.
     ((and org-return-follows-link
           (or (org-in-regexp org-ts-regexp-both nil t)
               (org-in-regexp org-tsr-regexp-both nil  t)
               (org-in-regexp org-any-link-re nil t)
               ;; Adam -- add org-wikinodes to list of regexp types
               (and (eq org-wikinodes-active t)
                    (org-in-regexp org-wikinodes-camel-regexp nil t)
                    (not (org-at-heading-p)))))
      (call-interactively #'org-open-at-point))
     ;; Insert newline in heading, but preserve tags.
     ((and (not (bolp))
           (save-excursion (beginning-of-line)
                           (let ((case-fold-search nil))
                             (looking-at org-complex-heading-regexp))))
      ;; At headline.  Split line.  However, if point is on keyword,
      ;; priority cookie or tags, do not break any of them: add
      ;; a newline after the headline instead.
      (let ((tags-column (and (match-beginning 5)
                              (save-excursion (goto-char (match-beginning 5))
                                              (current-column))))
            (string
             (when (and (match-end 4) (org-point-in-group (point) 4))
               (delete-and-extract-region (point) (match-end 4)))))
        ;; Adjust tag alignment.
        (cond
         ((not (and tags-column string)))
         (org-auto-align-tags (org-set-tags nil t))
         (t (org--align-tags-here tags-column))) ;preserve tags column
        (end-of-line)
        (org-show-entry)
        (if indent (newline-and-indent) (newline))
        (when string (save-excursion (insert (org-trim string))))))
     ;; In a list, make sure indenting keeps trailing text within.
     ((and indent
           (not (eolp))
           (org-element-lineage context '(item)))
      (let ((trailing-data
             (delete-and-extract-region (point) (line-end-position))))
        (newline-and-indent)
        (save-excursion (insert trailing-data))))
     (t (if indent (newline-and-indent) (newline)))))))

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.