Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-31 Thread Nicolas Richard
Thorsten Jolitz tjol...@gmail.com writes:
 Nicolas Richard theonewiththeevill...@yahoo.fr writes:
 Thanks for the URL. The description looks great but why not patch
 outline.el instead of making it an external library ? Is there an
 incompatibility ?

 Well, outshine merges quite old extension libraries for outline like
 outline-magic (Carsten Dominik) and out-xtra (Per Abrahamsen) and adds
 lots of new stuff. Why did the old guys back then wrote extensions
 instead of patching outline? No idea ...

Sorry, I only meant to speak about outline-magic.

Thanks for the detailed descriptions though.

-- 
Nico.



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-30 Thread Nicolas Richard
Hello Bastien,

Bastien b...@gnu.org writes:
 I think it's fine to bind `org-narrow-to-subtree' in narrow-map.
 It's basically to enjoy the `C-x n prefix', which is natural here.

I agree, but it is not compatible with keeping it only for org-mode
buffers while using something else for some other modes, which is what
you suggest next :

 I applied your patch, but a good continuation would be to have
 C-h n s bound to `outline-narrow-to-subtree' in outline-mode and
 to `org-narrow-to-subtree' in org-mode, instead of just relying
 on one single function.

 This requires simplifying `org-narrow-to-subtree' and creating
 `outline-narrow-to-subtree' in emacs.

 What do you think?

I think backporting narrow-to-subtree to outline is a very good move.
(Other things would be cool in outline, e.g. why does it not have
outline-cycle ? But that's a longer story, I guess.)

Another possibility : wouldn't it make sense to hijack narrow-to-defun
for this ? In fact, it used to be that way, but then it was changed in
76fa979225a2a31f7be6d366c48750d4f7abe458 (and then reverted, and then
the revert was reverted, and I have no idea why).

Looking more closely, the current behaviour is partly buggy, e.g. with a
file like :

* one
** two
** three
* four

When point is on the second line and C-M-e is used, we end up on the
first line ! I see two reasons for this or similar failures :
- One is a bug in org-forward-heading-same-level (I provide a patch
below).
- The other is because org-backward-element doesn't fully satisfy the
beginning-of-defun usual protocol since it sometimes signals an error.

Here's a test for catching the bug in org-forward-heading-same-level:
(org-test-with-temp-text \
* one
* two

   (goto-line 2)
   (org-forward-heading-same-level -1)
   (should (bobp)))

And here's the patch for org-forward-heading-same-level.

Modified   lisp/org.el
diff --git a/lisp/org.el b/lisp/org.el
index 0e15710..741c9b5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -23328,9 +2,10 @@ non-nil it will also look at invisible ones.
're-search-forward))
   (count (if arg (abs arg) 1))
   (result (point)))
-  (while (and (prog1 ( count 0)
-   (forward-char (if (and arg ( arg 0)) -1 1)))
-  (funcall f org-outline-regexp-bol nil 'move))
+  (while (and ( count 0)
+ (progn
+   (forward-char (if (and arg ( arg 0)) -1 1))
+   (funcall f org-outline-regexp-bol nil 'move)))
 (let ((l (- (match-end 0) (match-beginning 0) 1)))
   (cond (( l level) (setq count 0))
 ((and (= l level)

Want a git-format-patch one ?

Also, here's a test where I don't know what should happen (currently
signals a user-error) :

(org-test-with-temp-text \
one
* two

   (goto-line 2)
   (org-backward-element)
   (should t))


-- 
Nico.



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-30 Thread Thorsten Jolitz
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 I think backporting narrow-to-subtree to outline is a very good move.
 (Other things would be cool in outline, e.g. why does it not have
 outline-cycle ? But that's a longer story, I guess.)

It does via outline-magic.el (now maintained by me:
https://github.com/tj64/outline-magic), and the short story is (my
interpretation!) that outline-magic.el was the first step of Carsten
Dominik towards Org-mode, thus it adds many org-style features to
outline-mode. He later abandoned it in favor of Org-mode and asked me to
take over maintainance when I showed interest in it.

It is fully integrated (and partly improved and expanded) in outshine.el
now, so if you want Org-like behaviour for outline-(minor)-mode you
should really use outshine rather than outline-magic.

 outline with outshine outshines outline 

-- 
cheers,
Thorsten




Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-30 Thread Nicolas Richard
Thorsten Jolitz tjol...@gmail.com writes:

 Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 I think backporting narrow-to-subtree to outline is a very good move.
 (Other things would be cool in outline, e.g. why does it not have
 outline-cycle ? But that's a longer story, I guess.)

 It does via outline-magic.el (now maintained by me:
 https://github.com/tj64/outline-magic), and the short story is (my

 It is fully integrated (and partly improved and expanded) in outshine.el

Thanks for the URL. The description looks great but why not patch
outline.el instead of making it an external library ? Is there an
incompatibility ?

-- 
Nico.



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-30 Thread Thorsten Jolitz
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 Thorsten Jolitz tjol...@gmail.com writes:

 Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 I think backporting narrow-to-subtree to outline is a very good move.
 (Other things would be cool in outline, e.g. why does it not have
 outline-cycle ? But that's a longer story, I guess.)

 It does via outline-magic.el (now maintained by me:
 https://github.com/tj64/outline-magic), and the short story is (my

 It is fully integrated (and partly improved and expanded) in outshine.el

 Thanks for the URL. The description looks great but why not patch
 outline.el instead of making it an external library ? Is there an
 incompatibility ?

Well, outshine merges quite old extension libraries for outline like
outline-magic (Carsten Dominik) and out-xtra (Per Abrahamsen) and adds
lots of new stuff. Why did the old guys back then wrote extensions
instead of patching outline? No idea ... 

Outshine was never meant to replace outline, and there is a conceptual
incompability. Outshine trys to bring Org-mode's lookfeel to
programming major-modes, meaning that headlines are outcommented
Org headlines, e.g.

,
| ;; ** 2nd Level
`

But pure outline users tend to fold whatever they want, e.g. function defs
in elisp etc., and thats too much of a conceptual mismatch to merge it
in one library. 

Outshine users should structure their source-files just like Org files,
only with outcommented headlines, then many things will work just like
in Org-mode. Additional folding features could be added like in Org-mode
(plain list, src-blocks etc), but the Org-headline as core structural
element is mandatory in both Org-mode and Outshine.

Thus outshine is one option for outline users, but not the only
one. They can still use plain old outline and define whatever they want
as outline-regexp.

But, btw, navi-mode gives you that too, so its possible to have the best
of both worlds:

E.g, after doing 'M-s n' (M-x navi-search-and-switch) in outshine.el, 

doing 'f' in the *Navi* buffer gives:

,
| 194 matches for ^[[:space:]]*(def[maus][^elt][a-z]*\*?  in buffer: 
outshine.el
| 344:(defun outshine-compatible-face (inherits specs)
| 695:(defmacro outshine-define-key-with-fallback
| 734:(defun outshine-chomp (str)
| 744:(defun outshine-set-outline-regexp-base ()
| 757:(defun outshine-normalize-regexps ()
| 772:(defun outshine-modern-header-style-in-elisp-p (optional buffer)
| 785:(defun outshine-calc-comment-region-starter ()
| 795:(defun outshine-calc-comment-padding ()
| 811:(defun outshine-calc-outline-regexp ()
| 834:(defun outshine-calc-outline-level ()
| 871:(defun outshine-set-local-outline-regexp-and-level
| 888:(defun outshine-write-hidden-lines-cookies ()
| 902:(defun outshine-hidden-lines-cookie-status-changed-p ()
| 912:(defun outshine-set-hidden-lines-cookie ()
| 949:(defun outshine-calc-outline-string-at-level (level)
| 961:(defun outshine-calc-outline-base-string-at-level (level)
| 968:(defun outshine-transform-normalized-outline-regexp-base-to-string ()
| 976:(defun outshine-make-promotion-headings-list (max-level)
| 990:(defun outshine-fontify-headlines (outline-regexp) ...
`

doing 'v' gives

,
| 55 matches for ^[[:space:]]*(def[vcgf][^l][a-z]+  in buffer: outshine.el
| 150:(defconst outshine-version 1.0
| 153:(defconst outshine-max-level 8
| 157:(defconst outshine-level-faces
| 162:(defconst outshine-outline-heading-end-regexp \n
| 167:(defconst outshine-oldschool-elisp-outline-regexp-base
| 171:(defconst outshine-speed-commands-default
| 249:(defconst outshine-comment-tag comment
| 256:(defvar outline-minor-mode-prefix \M-#
| 264:(defvar outline-promotion-headings nil
| 273:(defvar outshine-delete-leading-whitespace-from-outline-regexp-base-p 
nil
| 278:(defvar outshine-enforce-no-comment-padding-p nil
| 283:(defvar outshine-outline-regexp-base 
| 286:(defvar outshine-normalized-comment-start  ...
`

etc etc, here is the key-word search help for Emacs Lisp:

,
| [KEY] : [SEARCH]
| 
|   a : ALL
|   f : FUN
|   v : VAR
|   x : OBJ
|   b : DB
|   F : defun
|   V : defvar
|   C : defconst
|   G : defgroup
|   U : defcustom
|   A : defadvice
|   W : defalias
|   M : defmarcro
|   D : defface
|   S : defstruct
|   B : defsubst
|   L : defclass
|   I : define
|   J : declare
|   K : global-set-key
|   T : add-to-list
|   Q : setq
|   H : add-hook
| 

Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-28 Thread Bastien
Hi Nicolas,

Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 org-narrow-to-subtree is very nice, and I now have C-x n s hard-wired
 into my fingers, but it doesn't work when outline-regexp is too
 different from org-outline-regexp in Outline-but-non-Org mode buffers.

 It looked pretty easy to fix, so here is my suggestion, below. It should
 be rather harmless since it only affects non-Org buffers (and might have
 the nice side effect of allowing other commands to run in those buffers
 -- but I haven't checked.)

Applied in master, thanks,

-- 
 Bastien



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-28 Thread Bastien
Hi Nicolas,

Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 But now that I think about it, org mode simply should avoid narrow-map
 completely : users (me included) won't randomly try to run
 org-narrow-to-subtree outside of org buffers (and those who do deserve a
 bad error message) but they might want to give C-x n s a try if it is
 available.

 While writing a patch for changing that, I see that the code is:
 (if (boundp 'narrow-map)
 (org-defkey narrow-map s 'org-narrow-to-subtree)
   (org-defkey org-mode-map \C-xns 'org-narrow-to-subtree))
 (if (boundp 'narrow-map)
 (org-defkey narrow-map b 'org-narrow-to-block)
   (org-defkey org-mode-map \C-xnb 'org-narrow-to-block))
 (if (boundp 'narrow-map)
 (org-defkey narrow-map e 'org-narrow-to-element)
   (org-defkey org-mode-map \C-xne 'org-narrow-to-element))

 IOW, org.el purposely binds in narrow-map ! So now I don't get it :
 either it's in narrow-map and should be usable widely, or it's in
 org-mode-map only for org-mode files.

I think it's fine to bind `org-narrow-to-subtree' in narrow-map.
It's basically to enjoy the `C-x n prefix', which is natural here.

I applied your patch, but a good continuation would be to have
C-h n s bound to `outline-narrow-to-subtree' in outline-mode and
to `org-narrow-to-subtree' in org-mode, instead of just relying
on one single function.

This requires simplifying `org-narrow-to-subtree' and creating
`outline-narrow-to-subtree' in emacs.

What do you think?

-- 
 Bastien



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-25 Thread Nicolas Goaziou
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 But now that I think about it, org mode simply should avoid narrow-map
 completely : users (me included) won't randomly try to run
 org-narrow-to-subtree outside of org buffers (and those who do deserve a
 bad error message) but they might want to give C-x n s a try if it is
 available.

 While writing a patch for changing that, I see that the code is:
 (if (boundp 'narrow-map)
 (org-defkey narrow-map s 'org-narrow-to-subtree)
   (org-defkey org-mode-map \C-xns 'org-narrow-to-subtree))
 (if (boundp 'narrow-map)
 (org-defkey narrow-map b 'org-narrow-to-block)
   (org-defkey org-mode-map \C-xnb 'org-narrow-to-block))
 (if (boundp 'narrow-map)
 (org-defkey narrow-map e 'org-narrow-to-element)
   (org-defkey org-mode-map \C-xne 'org-narrow-to-element))

 IOW, org.el purposely binds in narrow-map ! So now I don't get it :
 either it's in narrow-map and should be usable widely, or it's in
 org-mode-map only for org-mode files.

I don't know the answer either, but it is strange indeed.

Carsten introduced it in 2008 in commit
6321ab8a852252ff242386eb9fef8ae12112f3a8, but the commit message is
rather terse. I'm CC'ing him for more information, hopefully.


Regards,

-- 
Nicolas Goaziou



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-24 Thread Nicolas Goaziou
Hello,

Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 org-narrow-to-subtree is very nice, and I now have C-x n s hard-wired
 into my fingers, but it doesn't work when outline-regexp is too
 different from org-outline-regexp in Outline-but-non-Org mode buffers.

`org-narrow-to-subtree' is an Org function. I don't think it should
bother about non Org mode buffers.

 It looked pretty easy to fix, so here is my suggestion, below. It should
 be rather harmless since it only affects non-Org buffers (and might have
 the nice side effect of allowing other commands to run in those buffers
 -- but I haven't checked.)

There was a discussion recently about making it easier to use some Org
features outside of Org. IIRC, the conclusion was that should not happen
at the core level, but as an external layer (e.g., a minor mode).


Regards,

-- 
Nicolas Goaziou



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-24 Thread Nicolas Richard
Nicolas Goaziou m...@nicolasgoaziou.fr writes:
 `org-narrow-to-subtree' is an Org function. I don't think it should
 bother about non Org mode buffers.

It's an Org function that grafts itself to narrow-map, which is globally
available.

I think it should try to have at least a sensible error message. The
current Before first headline isn't quite clear (my patch doesn't
address this, btw).

 It looked pretty easy to fix, so here is my suggestion, below. It should
 be rather harmless since it only affects non-Org buffers (and might have
 the nice side effect of allowing other commands to run in those buffers
 -- but I haven't checked.)

 There was a discussion recently about making it easier to use some Org
 features outside of Org.

I guess you're talking about
http://thread.gmane.org/gmane.emacs.orgmode/84782

 IIRC, the conclusion was that should not happen
 at the core level, but as an external layer (e.g., a minor mode).

If core Org functions only care about org-mode buffers, I guess it is
hard to make a minor mode that reuses some of Org to do its job. Unless
that mode is itself in the core of course. e.g. orgstruct-mode does that
and it needs some core support.

Anyway, my goal isn't to discuss a whole org minor mode.

-- 
Nico.



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-24 Thread Nicolas Goaziou
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 I think it should try to have at least a sensible error message. The
 current Before first headline isn't quite clear (my patch doesn't
 address this, btw).

Not in an Org mode buffer could be better indeed.

Anyway, this kind of change (including compatibility with outline.el)
belongs to the high-level function `org-narrow-to-subtree', not the very
specific `org-get-limited-outline-regexp'.

 I guess you're talking about
 http://thread.gmane.org/gmane.emacs.orgmode/84782

Correct.

 If core Org functions only care about org-mode buffers, I guess it is
 hard to make a minor mode that reuses some of Org to do its job. Unless
 that mode is itself in the core of course. e.g. orgstruct-mode does that
 and it needs some core support.

Orgstruct mode has indeed some core support, but that's a mistake IMO.


Regards,

-- 
Nicolas Goaziou



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-24 Thread Nicolas Richard
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 I think it should try to have at least a sensible error message. The
 current Before first headline isn't quite clear (my patch doesn't
 address this, btw).

 Not in an Org mode buffer could be better indeed.

 Anyway, this kind of change (including compatibility with outline.el)
 belongs to the high-level function `org-narrow-to-subtree', not the very
 specific `org-get-limited-outline-regexp'.

Agreed.

But now that I think about it, org mode simply should avoid narrow-map
completely : users (me included) won't randomly try to run
org-narrow-to-subtree outside of org buffers (and those who do deserve a
bad error message) but they might want to give C-x n s a try if it is
available.

While writing a patch for changing that, I see that the code is:
(if (boundp 'narrow-map)
(org-defkey narrow-map s 'org-narrow-to-subtree)
  (org-defkey org-mode-map \C-xns 'org-narrow-to-subtree))
(if (boundp 'narrow-map)
(org-defkey narrow-map b 'org-narrow-to-block)
  (org-defkey org-mode-map \C-xnb 'org-narrow-to-block))
(if (boundp 'narrow-map)
(org-defkey narrow-map e 'org-narrow-to-element)
  (org-defkey org-mode-map \C-xne 'org-narrow-to-element))

IOW, org.el purposely binds in narrow-map ! So now I don't get it :
either it's in narrow-map and should be usable widely, or it's in
org-mode-map only for org-mode files.

-- 
Nico.



Re: [O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-24 Thread Thorsten Jolitz
Nicolas Richard theonewiththeevill...@yahoo.fr writes:

 But now that I think about it, org mode simply should avoid narrow-map
 completely : users (me included) won't randomly try to run
 org-narrow-to-subtree outside of org buffers (and those who do deserve a
 bad error message) but they might want to give C-x n s a try if it is
 available.

BTW, if you use outshine and 

,
| (setq outshine-use-speed-commands t)
`

then you have most of the Org speed-commands available outside of
Org-mode too, including 'r' for narrow-to-subtree and 'w' for widen.

Try ? on an outshine heading to get this help buffer:

,
| User-defined Speed commands
| ===
| 
| Built-in Speed commands
| ===
| 
| Outline Navigation
| --
| n   (outshine-speed-move-safe (quote outline-next-visible-heading))
| p   (outshine-speed-move-safe (quote outline-previous-visible-heading))
| f   (outshine-speed-move-safe (quote outline-forward-same-level))
| b   (outshine-speed-move-safe (quote outline-backward-same-level))
| u   (outshine-speed-move-safe (quote outline-up-heading))
| j   outshine-goto
| g   outshine-refile
| 
| Outline Visibility
| --
| c   outline-cycle
| C   outshine-cycle-buffer
| r   outshine-narrow-to-subtree
| w   widen
| =   outshine-columns
| 
| Outline Structure Editing
| -
| ^   outline-move-subtree-up
|outline-move-subtree-down
| +   outline-demote
| -   outline-promote
| i   outshine-insert-heading
| ^   outshine-sort
| m   outline-mark-subtree
| 
| Clock Commands
| --
| I   outshine-clock-in
| O   outshine-clock-out
| 
| Meta Data Editing
| -
| t   outshine-todo
| ,   outshine-priority
| 0   (outshine-use-outorg (lambda nil (interactive) (org-priority 32)))
| 1   (outshine-use-outorg (lambda nil (interactive) (org-priority 65)))
| 2   (outshine-use-outorg (lambda nil (interactive) (org-priority 66)))
| 3   (outshine-use-outorg (lambda nil (interactive) (org-priority 67)))
| :   outshine-set-tags-command
| e   outshine-set-effort
| E   outshine-inc-effort
| v   org-agenda
| /   outshine-sparse-tree
| 
| Misc
| 
| o   outshine-open-at-point
| ?   outshine-speed-command-help
|(outshine-agenda-set-restriction-lock)
|(outshine-agenda-remove-restriction-lock)
| 
| [back]
`


-- 
cheers,
Thorsten




[O] Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)]

2014-07-22 Thread Nicolas Richard
Hello all,

org-narrow-to-subtree is very nice, and I now have C-x n s hard-wired
into my fingers, but it doesn't work when outline-regexp is too
different from org-outline-regexp in Outline-but-non-Org mode buffers.

It looked pretty easy to fix, so here is my suggestion, below. It should
be rather harmless since it only affects non-Org buffers (and might have
the nice side effect of allowing other commands to run in those buffers
-- but I haven't checked.)

From 70ccd90f98d07762d7ae228d67c387d674a69cee Mon Sep 17 00:00:00 2001
From: Nicolas Richard theonewiththeevill...@yahoo.fr
Date: Tue, 22 Jul 2014 18:29:00 +0200
Subject: [PATCH] Make org-get-limited-outline-regexp usable outside of org.

This allows org-narrow-to-subtree to function in Outline mode.

* lisp/org-macs.el (org-get-limited-outline-regexp): Use
  outline-regexp instead of org-outline-regexp when not in Org mode.
---
 lisp/org-macs.el | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 96265ec..78174df 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -352,11 +352,16 @@ point nowhere.
 (defun org-get-limited-outline-regexp ()
   Return outline-regexp with limited number of levels.
 The number of levels is controlled by `org-inlinetask-min-level'
-  (if (or (not (derived-mode-p 'org-mode)) (not (featurep 'org-inlinetask)))
-  org-outline-regexp
-(let* ((limit-level (1- org-inlinetask-min-level))
-  (nstars (if org-odd-levels-only (1- (* limit-level 2)) limit-level)))
-  (format \\*\\{1,%d\\}  nstars
+  (cond ((not (derived-mode-p 'org-mode))
+outline-regexp)
+   ((not (featurep 'org-inlinetask))
+org-outline-regexp)
+   (t
+(let* ((limit-level (1- org-inlinetask-min-level))
+   (nstars (if org-odd-levels-only
+   (1- (* limit-level 2))
+ limit-level)))
+  (format \\*\\{1,%d\\}  nstars)
 
 (defun org-format-seconds (string seconds)
   Compatibility function replacing format-seconds.
-- 
2.0.2