emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] link interfering with brackets when abbreviated


From: Michael Brand
Subject: Re: [O] link interfering with brackets when abbreviated
Date: Thu, 27 Feb 2014 21:01:34 +0100

Hi Nicolas

On Thu, Feb 27, 2014 at 11:28 AM, Nicolas Goaziou <address@hidden> wrote:
> The only really predictable behaviour is: "open the link under point".
> Everything else is arguable.

What for me is a conflict between ...

    1) There are arguments to change - as you recently did in master -
       org-open-at-point to open only if there is a link _at point_.
       Just as its function name tells.

    2) As a user I would like to have the possibility to open a link
       between point and end of line without having to navigate to the
       exact column. Also in modes other than Org.

... I solve for myself with the following function bound to "C-c o"
(not "C-c C-o"). It moves to and opens the first link between point
and end of line by simply trying point by point until it works the
current org-open-at-point from master that opens only when point is on
a link:

#+BEGIN_SRC emacs-lisp
  (defun f-open-link-between-point-and-eol ()
    "Move to and open first link between point and end of line.
  As long as not yet at end of line and as long as
  `org-open-at-point' or `browse-url-at-point' gives an error
  advance point by one character. For Org and other major modes."
    (interactive)
    (let ((p (point)) (err t))
      (while (and (not (eolp))
                  (setq err (not (ignore-errors
                                   (or (cond
                                        ;; Org mode
                                        ((eq major-mode 'org-mode)
                                         (org-open-at-point))
                                        ;; Maybe more major modes here
                                        ;; [...]
                                        ;; All other major modes
                                        (t
                                         (browse-url-at-point)))
                                       t)))))
        (forward-char))
      (when err
        (goto-char p)
        (user-error "No link between point and end of line"))))
#+END_SRC

The above function does not only work for Org link and URL in Org mode
but also for URL in any other major mode. The definition of what
should be the alternative link when there is no link at the starting
point is simply delegated to org-open-at-point and
browse-url-at-point. This simplification makes it slow for links
towards the end or not present in long lines. There is plenty of room
for a better implementation than I did with this very simple first
approach.

In the case that, depending on user feedback, even "C-c C-o" itself
should move to the first link between point and end of line - or
whatever other link - also when there is no link at the starting
point, I suggest to keep org-open-at-point to open only when point is
on a link and to wrap this move into a new function, named e. g.
org-open-between-point-and-eol to be bound to "C-c C-o".

The simplified solution with f-open-link-between-point-and-eol already
covers all my use cases of the old org-open-at-point. The
predictability of what will be the alternative link remains arguable.
I find its predictability at least better than with the old
org-open-at-point. And last but not least also the original issue

    #+LINK: link-abbreviation http://www.orgmode.org/#
    1) [ ] [[http://www.orgmode.org/#docs]]
    2) [[link-abbreviation:docs]]
    3) [ ] [[link-abbreviation:docs]]

of this thread with point on the character "3" is of course solved for
me.

Michael



reply via email to

[Prev in Thread] Current Thread [Next in Thread]