emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [RFC] Change visibility for bracket links


From: Stig Brautaset
Subject: Re: [O] [RFC] Change visibility for bracket links
Date: Sat, 22 Oct 2016 03:02:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin)

Clément Pit--Claudel <address@hidden> writes:

> On 2016-10-13 08:30, Nicolas Goaziou wrote:
>> I understand what `prettify-symbols-mode' is. My real problem is
>> understanding how it can help with links in Org. In particular, I'd like
>> to see it, or any other mechanism, turn
>> 
>>   [[http://orgmode.org][Org mode]]
>> 
>> displayed as
>> 
>>   Org mode
>> 
>> into
>> 
>>   [Org mode]
>> 
>> when point is near _any_ of the boundaries and doesn't trigger anything
>> on anything not related to an Org link.
>> 
>> I don't know if that would be sufficient to make it useful, but it needs
>> to be as subtle as possible. We already have a not-so-subtle solution
>> with visible square brackets.
>
> Hey Nicolas,
>
> Something like this?
>
>     (defvar-local org-show-link--beg nil)
>     (defvar-local org-show-link--end nil)
>
>     (defun org-show-link--reveal-at-point (&rest _)
>       "Possibly reveal link markup around point."
>       (unless (and org-show-link--beg org-show-link--end)
>         (setq org-show-link--beg (make-marker)
>               org-show-link--end (make-marker)))
>       (when (and (marker-position org-show-link--beg)
>                  (marker-position org-show-link--end))
>         (unless (<= org-show-link--beg (point) org-show-link--end)
>           (save-excursion (font-lock-fontify-region org-show-link--beg 
> org-show-link--end))
>           (set-marker org-show-link--beg nil)
>           (set-marker org-show-link--end nil)))
>       (save-excursion
>         (when (org-in-regexp org-bracket-link-regexp 1)
>           (set-marker org-show-link--beg (match-beginning 0))
>           (set-marker org-show-link--end (match-end 0))
>           (with-silent-modifications
>             (remove-text-properties (match-beginning 2) (1+ (match-beginning 
> 2)) '(invisible))
>             (remove-text-properties (1- (match-end 2)) (match-end 2) 
> '(invisible)))))
>       (message "%S" org-show-link--end))
>
>     (defun org-show-link-setup ()
>       (add-hook 'post-command-hook #'org-show-link--reveal-at-point t t))
>
>     (add-hook 'org-mode-hook #'org-show-link-setup)
>
> Running it before opening an Org buffer with links should be enough to
> make it work (links brackets will be hidden until point is next to or
> inside the link). It's a quick draft, of course — there are still
> small issues. But it should give an idea of what my original proposal
> was about.

I love this! I have had problems with editing links at the start of
lines etc, and this seems to solve it. I would love something similar
for *bold* and /italics/ too.

Stig



reply via email to

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