From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Christopher J. White" Subject: Re: org-link minor mode Date: Tue, 14 Aug 2012 06:57:31 -0400 Message-ID: <502A2F1B.5030507@grierwhite.com> References: Reply-To: orgmode@grierwhite.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:40315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1Eob-0001IU-3h for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 06:57:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1EoY-0001zt-70 for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 06:57:37 -0400 Received: from mail26c25.carrierzone.com ([64.29.147.36]:48262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1EoX-0001zX-Vx for emacs-orgmode@gnu.org; Tue, 14 Aug 2012 06:57:34 -0400 Received: from [11.1.1.76] (pool-108-7-149-89.bstnma.east.verizon.net [108.7.149.89]) (authenticated bits=0) by mail26c25.carrierzone.com (8.13.6/8.13.1) with ESMTP id q7EAvUkB003736 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 14 Aug 2012 10:57:32 GMT In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 > >