emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-link minor mode
@ 2012-08-12 20:25 Sean O'Halpin
  2012-08-14  7:49 ` Bastien
  2012-08-14 10:57 ` Christopher J. White
  0 siblings, 2 replies; 7+ messages in thread
From: Sean O'Halpin @ 2012-08-12 20:25 UTC (permalink / raw)
  To: Org Mode

Hi,

I've been hacking this weekend to try to create a minor mode that
enables org-mode bracket links in modes other than org-mode.

I believe this has been mooted before
(e.g. http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00573.html).

The following codes works for me but I'm sure it could be improved.

I'm an elisp noob so I'd very much appreciate feedback on the approach
I'm taking.  For example, I'm not sure how to prevent turning on
org-link-minor-mode from an org-mode buffer - advice would be welcome.

Regards,
Sean

#+begin_src emacs-lisp

(require 'org)

(define-minor-mode org-link-minor-mode
  "Toggle display of org-mode style bracket links in non-org-mode buffers."
  :lighter " org-link"
  (let ((org-link-minor-mode-keywords (list
'(org-activate-bracket-links (0 'org-link t)))))
    (save-excursion
      (save-match-data
        (goto-char (point-min))
        (if org-link-minor-mode
            (progn
              (font-lock-add-keywords nil org-link-minor-mode-keywords t)
              (set (make-local-variable 'org-descriptive-links)
org-descriptive-links)
              (if org-descriptive-links (add-to-invisibility-spec '(org-link)))
              (font-lock-fontify-buffer)
              )
          (progn
            (font-lock-remove-keywords nil org-link-minor-mode-keywords)
            (org-remove-from-invisibility-spec '(org-link))
            (while (re-search-forward org-bracket-link-regexp nil t)
              ;; Remove all org-link properties
              (remove-text-properties (match-beginning 0) (match-end
0) (text-properties-at (match-beginning 0)))
              )
            )
          )))))

(provide 'org-link-minor-mode)

#+end_src

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-12 20:25 org-link minor mode Sean O'Halpin
@ 2012-08-14  7:49 ` Bastien
  2012-08-18  4:07   ` Sean O'Halpin
  2012-08-14 10:57 ` Christopher J. White
  1 sibling, 1 reply; 7+ messages in thread
From: Bastien @ 2012-08-14  7:49 UTC (permalink / raw)
  To: Sean O'Halpin; +Cc: Org Mode

"Sean O'Halpin" <sean.ohalpin@gmail.com> writes:

> I've been hacking this weekend to try to create a minor mode that
> enables org-mode bracket links in modes other than org-mode.
>
> I believe this has been mooted before
> (e.g. http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00573.html).

Yes.  This might especially be useful in modes where people use
orgstruct as well -- and could well end up being part of orgstruct,
if that's not too invasive.

> The following codes works for me but I'm sure it could be improved.
>
> I'm an elisp noob so I'd very much appreciate feedback on the approach
> I'm taking.  For example, I'm not sure how to prevent turning on
> org-link-minor-mode from an org-mode buffer - advice would be welcome.

Simply use

(unless (derived-mode-p 'org-mode)

on the top of your function?

Also, you might want to check `org-fontify-like-in-org-mode': for any
regexp (including links) that you find in your buffer, you can fontify
it like in org-mode.

HTH,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-12 20:25 org-link minor mode Sean O'Halpin
  2012-08-14  7:49 ` Bastien
@ 2012-08-14 10:57 ` Christopher J. White
  2012-08-18  0:02   ` Sean O'Halpin
  1 sibling, 1 reply; 7+ messages in thread
From: Christopher J. White @ 2012-08-14 10:57 UTC (permalink / raw)
  To: emacs-orgmode

This is pretty cool, Sean.  One issue I'm having is that it does not 
properly handle "breaking" the link:

"[[link][description]]" is displayed as "link", with the cursor after 
link.  In org-mode, if I hit backspace, it deletes the trailing ']' and 
changes the display to "[[link][description]".  But using this minor 
mode, it keeps still just shows "link".  If I turn minor mode off again, 
it's clear that the trailing bracket was deleted.

I took a look at the org source regarding links, but I couldn't quite 
figure out how org does this.  It just calls org-delete-backward-char, 
which doesn't appear to have any magic for links.

Thanks
...cj


On 8/12/12 4:25 PM, Sean O'Halpin wrote:
> Hi,
>
> I've been hacking this weekend to try to create a minor mode that
> enables org-mode bracket links in modes other than org-mode.
>
> I believe this has been mooted before
> (e.g. 
> http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00573.html).
>
> The following codes works for me but I'm sure it could be improved.
>
> I'm an elisp noob so I'd very much appreciate feedback on the approach
> I'm taking.  For example, I'm not sure how to prevent turning on
> org-link-minor-mode from an org-mode buffer - advice would be welcome.
>
> Regards,
> Sean
>
> #+begin_src emacs-lisp
>
> (require 'org)
>
> (define-minor-mode org-link-minor-mode
>    "Toggle display of org-mode style bracket links in non-org-mode 
> buffers."
>    :lighter " org-link"
>    (let ((org-link-minor-mode-keywords (list
> '(org-activate-bracket-links (0 'org-link t)))))
>      (save-excursion
>        (save-match-data
>          (goto-char (point-min))
>          (if org-link-minor-mode
>              (progn
>                (font-lock-add-keywords nil org-link-minor-mode-keywords t)
>                (set (make-local-variable 'org-descriptive-links)
> org-descriptive-links)
>                (if org-descriptive-links (add-to-invisibility-spec 
> '(org-link)))
>                (font-lock-fontify-buffer)
>                )
>            (progn
>              (font-lock-remove-keywords nil org-link-minor-mode-keywords)
>              (org-remove-from-invisibility-spec '(org-link))
>              (while (re-search-forward org-bracket-link-regexp nil t)
>                ;; Remove all org-link properties
>                (remove-text-properties (match-beginning 0) (match-end
> 0) (text-properties-at (match-beginning 0)))
>                )
>              )
>            )))))
>
> (provide 'org-link-minor-mode)
>
> #+end_src
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-14 10:57 ` Christopher J. White
@ 2012-08-18  0:02   ` Sean O'Halpin
  0 siblings, 0 replies; 7+ messages in thread
From: Sean O'Halpin @ 2012-08-18  0:02 UTC (permalink / raw)
  To: orgmode; +Cc: emacs-orgmode

On Tue, Aug 14, 2012 at 11:57 AM, Christopher J. White
<orgmode@grierwhite.com> wrote:
> This is pretty cool, Sean.  One issue I'm having is that it does not
> properly handle "breaking" the link:

Thanks for trying it out. I think I've fixed the link "breaking"
problem (using font-lock-unfontify-region-function). Source in github
at: https://github.com/seanohalpin/org-link-minor-mode

Regards,
Sean

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-14  7:49 ` Bastien
@ 2012-08-18  4:07   ` Sean O'Halpin
  2012-08-18 15:07     ` Bastien
  0 siblings, 1 reply; 7+ messages in thread
From: Sean O'Halpin @ 2012-08-18  4:07 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode

On Tue, Aug 14, 2012 at 8:49 AM, Bastien <bzg@gnu.org> wrote:
> "Sean O'Halpin" <sean.ohalpin@gmail.com> writes:
>
>> I've been hacking this weekend to try to create a minor mode that
>> enables org-mode bracket links in modes other than org-mode.
[snip]
> Yes.  This might especially be useful in modes where people use
> orgstruct as well -- and could well end up being part of orgstruct,
> if that's not too invasive.

I see it as orthogonal to orgstruct - they could happily co-exist side by side.
I've just tested that though and it seems they don't. I'll try to fix that.

>> I'm not sure how to prevent turning on org-link-minor-mode
>> from an org-mode buffer

> Simply use
>
> (unless (derived-mode-p 'org-mode)
>
> on the top of your function?

Thanks - I used your suggestion as you can see here:

  https://github.com/seanohalpin/org-link-minor-mode/blob/master/org-link-minor-mode.el

I realised the problem I had was that I can't prevent entering the minor mode
because by the time I check for org-mode, the minor mode has already been
entered so I have to turn it off again.

BTW, I've refactored the code to simplify it and added more link types.

Regards,
Sean

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-18  4:07   ` Sean O'Halpin
@ 2012-08-18 15:07     ` Bastien
  2012-08-19 12:16       ` Sean O'Halpin
  0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2012-08-18 15:07 UTC (permalink / raw)
  To: Sean O'Halpin; +Cc: Org Mode

Hi Sean,

I just added links to your code in worg/org-hacks.org and
worg/org-contrib/index.org -- thanks!

"Sean O'Halpin" <sean.ohalpin@gmail.com> writes:

> I see it as orthogonal to orgstruct - they could happily co-exist side by side.
> I've just tested that though and it seems they don't. I'll try to fix
> that.

Okay, let us know how it goes!

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-link minor mode
  2012-08-18 15:07     ` Bastien
@ 2012-08-19 12:16       ` Sean O'Halpin
  0 siblings, 0 replies; 7+ messages in thread
From: Sean O'Halpin @ 2012-08-19 12:16 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode

On Sat, Aug 18, 2012 at 4:07 PM, Bastien <bzg@altern.org> wrote:
> Hi Sean,
>
> I just added links to your code in worg/org-hacks.org and
> worg/org-contrib/index.org -- thanks!

Thanks!

>> I see it as orthogonal to orgstruct - they could happily co-exist side by side.
>> I've just tested that though and it seems they don't. I'll try to fix
>> that.
>
> Okay, let us know how it goes!
>
Certainly (though it might take a little longer...)

Regards,
Sean

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-08-19 12:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-12 20:25 org-link minor mode Sean O'Halpin
2012-08-14  7:49 ` Bastien
2012-08-18  4:07   ` Sean O'Halpin
2012-08-18 15:07     ` Bastien
2012-08-19 12:16       ` Sean O'Halpin
2012-08-14 10:57 ` Christopher J. White
2012-08-18  0:02   ` Sean O'Halpin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).