From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Vorobiev Subject: Re: Org-mode outside Org-mode Date: Wed, 24 Apr 2013 09:20:17 -0500 Message-ID: References: <87txoc7jvr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b5d63e891b35504db1c01c5 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:60911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV0Ys-0005yP-O7 for emacs-orgmode@gnu.org; Wed, 24 Apr 2013 10:20:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UV0Yq-0000WX-7s for emacs-orgmode@gnu.org; Wed, 24 Apr 2013 10:20:42 -0400 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]:38521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV0Yp-0000WF-UQ for emacs-orgmode@gnu.org; Wed, 24 Apr 2013 10:20:40 -0400 Received: by mail-pb0-f49.google.com with SMTP id rp2so472132pbb.36 for ; Wed, 24 Apr 2013 07:20:38 -0700 (PDT) In-Reply-To: <87txoc7jvr.fsf@gmail.com> 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: Thorsten Jolitz Cc: emacs-orgmode --047d7b5d63e891b35504db1c01c5 Content-Type: text/plain; charset=ISO-8859-1 First of all, thank you for the tutorial and the code! Outshine has become a major component of my workflow, I use it in all my source code buffers (sql, R, elisp). I have one question/proposal regarding key bindings. Outshine binds TAB to outshine-cycle-subtree which only does something useful (calls outshine-cycle) when the point is on a header line, otherwise it prints a message. TAB is used heavily in various source code -related modes (yasnippets, smart-tab, etc. http://www.emacswiki.org/emacs/TabCompletion is a great source for those) - the behavior which I don't want to lose. There is some support of other TAB behaviors in outline-cycle but it is not used (and it ignores the user-defined bindings). A while back I wrote a macro (based on the advice in http://stackoverflow.com/a/2494384/973603) which allows to activate minor mode bindings when a condition is true and fall back to previous bindings otherwise: (defmacro define-key-with-fallback (keymap key def condition &optional mode) "Define key with fallback. Binds KEY to definition DEF in keymap KEYMAP, the binding is active when the CONDITION is true. Otherwise turns MODE off and re-enables previous definition for KEY. If MODE is nil, tries to recover it by stripping off \"-map\" from KEYMAP name." `(define-key ,keymap ,key (lambda () (interactive) (if ,condition ,def (let* ((,(if mode mode (let* ((keymap-str (symbol-name keymap)) (mode-name-end (- (string-width keymap-str) 4))) (if (string= "-map" (substring keymap-str mode-name-end)) (intern (substring keymap-str 0 mode-name-end)) (error "Could not deduce mode name from keymap name (\"-map\" missing?)")))) nil) (original-func (key-binding ,key))) (call-interactively original-func)))))) So now I can just do (define-key-with-fallback outline-minor-mode-map (kbd "TAB") (outline-cycle 1) (outline-on-heading-p)) and have my yasnippets and smart indentation/completion active again. My question is am I reinventing the wheel? Is there a function/macro in org-mode or elsewhere that would allow me define key bindings with fallback? Thanks again, Alex On Fri, Mar 15, 2013 at 10:39 AM, Thorsten Jolitz wrote: > > Hi List, > > there is a now a tutorial on Worg describing the recently announced new > libraries for using (concepts and functionality of) Org-mode when > outside Org-mode: > > ,----------------------------------------------------------- > | http://orgmode.org/worg/org-tutorials/org-outside-org.html > `----------------------------------------------------------- > > Besides using the 'well-known' orgstruct-minor-mode, you can now: > > - use outline-minor-mode with *outshine.el* extensions and structure > your file with outshine-style headlines, giving your source-code files > the look&feel of Org-mode files. Should work in any major-mode. > > - use *outorg.el* to edit complete subtrees or the whole file as > Org-mode in a temporary Org-mode edit-buffer. Depends on outshine. > > - use *navi-mode.el* to open an occur-like indirect buffer for > super-fast navigation and structure-editing (as well as other common > actions on subtrees) in the associated original-buffer - all with > one-key commands in a read-only buffer. A kind of customizable > remote-control for the original-buffer with many views combining > headline and keyword searches and easy switching between the > associated buffers. Depends somehow on outshine too, but to a much > lesser degree than outorg.el > > And of course you have Francois Pinard's *poporg.el* and can (completely > independent from orgstruct or outshine): > > - edit atomic comment-sections (anywhere in a source-code buffer, no > matter what major-mode) in a temporary Org-mode edit-buffer. Thus, > while *outorg* gives you a whole subtree with headline and source-code > blocks in a temporary Org-mode edit-buffer, *poporg* gives you only > the comment-string near point and nothing else, so that both libraries > complement each other really well in their usage. > > For more details see the tutorial on Worg. > > -- > cheers, > Thorsten > > > > --047d7b5d63e891b35504db1c01c5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
First of all, thank you for the tutorial and the code! Out= shine has become=A0
a major component of my workflow, I use it in all my source code buffers (sql, R, elisp).=A0

I have one questi= on/proposal regarding key bindings. Outshine binds TAB
to outshine-cycle-subtree which only does something useful (c= alls outshine-cycle)=A0
when the point is on a header line, otherwise = it prints a message. TAB is used
=A0heavily in various source code -= related modes (yasnippets, smart-tab, etc.=A0
http://www.emacswiki.org/em= acs/TabCompletion is a great source for those) - the=A0
behavior which I don't want to lose. There is= some support of other TAB behaviors in=A0
outline-cycle but it i= s not used (and it ignores the user-defined bindings).

A while back I wrote a macro (based on the advice in=A0
= htt= p://stackoverflow.com/a/2494384/973603) which allows to activate minor = mode
bindings when a condition is true and fall back to previous bindings otherwise:

(defmacro def= ine-key-with-fallback (keymap key def condition &optional mode)=A0
=A0"Define key with fallback. Binds KEY to definition DEF in key= map KEYMAP, the=A0
=A0 binding is active when the CONDITION is true. Otherwise turns MODE= off and=A0
=A0 re-enables previous definition for KEY. If MODE i= s nil, tries to recover it by=A0
=A0 stripping off \"-map\&q= uot; from KEYMAP name."=A0
=A0 `(define-key ,keymap ,key (lambda () (interactive)
=A0 =A0 =A0(if ,condition ,def= =A0
=A0 =A0 =A0 =A0(let* ((,(if mode mode=A0
=A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(let* ((keymap-str (symbol-name keymap))= =A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(mode-name-end (- (string-width keymap-str) 4)))=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (string=3D "-= map" (substring keymap-str mode-name-end))
=A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (intern (substring keymap-str 0 mode-na= me-end))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (err= or "Could not deduce mode name from keymap name (\"-map\" mi= ssing?)"))))=20 nil)=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= (original-func (key-binding ,key)))
=A0 =A0 =A0 =A0 =A0 =A0(call-= interactively original-func))))))

So now I can jus= t do

(define-key-with-fallback outline-minor-mode-map (kbd "TAB")=20 (outline-cycle 1) (outline-on-heading-p))=A0
=

and have my yasnippets and smart indentation/completion= active again. My question is am I reinventing=A0
the wheel? Is t= here a function/macro in org-mode or elsewhere that would allow me define k= ey bindings
with fallback?

Thanks again,
Alex


On Fri, Mar 15, 2013 at 10:39 AM, Thorsten Jolitz <tjolitz@gmail.= com> wrote:

Hi List,

there is a now a tutorial on Worg describing the recently announced new
libraries for using (concepts and functionality of) Org-mode when
outside Org-mode:

,-----------------------------------------------------------
| http://orgmode.org/worg/org-tutorials/org-outside-org.html<= /a>
`-----------------------------------------------------------

Besides using the 'well-known' orgstruct-minor-mode, you can now:
- use outline-minor-mode with *outshine.el* extensions and structure
=A0 your file with outshine-style headlines, giving your source-code files<= br> =A0 the look&feel of Org-mode files. Should work in any major-mode.

- use *outorg.el* to edit complete subtrees or the whole file as
=A0 Org-mode in a temporary Org-mode edit-buffer. Depends on outshine.

- use *navi-mode.el* to open an occur-like indirect buffer for
=A0 super-fast navigation and structure-editing (as well as other common =A0 actions on subtrees) in the associated original-buffer - all with
=A0 one-key commands in a read-only buffer. A kind of customizable
=A0 remote-control for the original-buffer with many views combining
=A0 headline and keyword searches and easy switching between the
=A0 associated buffers. Depends somehow on outshine too, but to a much
=A0 lesser degree than outorg.el

And of course you have Francois Pinard's *poporg.el* and can (completel= y
independent from orgstruct or outshine):

- edit atomic comment-sections (anywhere in a source-code buffer, no
=A0 matter what major-mode) in a temporary Org-mode edit-buffer. Thus,
=A0 while *outorg* gives you a whole subtree with headline and source-code<= br> =A0 blocks in a temporary Org-mode edit-buffer, *poporg* gives you only
=A0 the comment-string near point and nothing else, so that both libraries<= br> =A0 complement each other really well in their usage.

For more details see the tutorial on Worg.

--
cheers,
Thorsten




--047d7b5d63e891b35504db1c01c5--