Re: [O] S-M-right problem in orgstruct-mode

2013-03-10 Thread Christopher Schmidt
Bastien  writes:

Hi there,

> Alan Schmitt  writes:
>
>> even though the cursor is on a structure element. Maybe a more
>> information "this function is disabled" would work (if it's possible).
>> But as I said, it's a nitpick.

thank you very much for testing the patch.

> I agree with Alan, let's update the user-error to something more
> informative -- Christopher, thanks a lot for the patch!  Feel free
> to commit and push when you want.

Disabled commands are no-ops now.  I pushed this to origin/master.

03b1edf org.el: Disable {pro,de}motion commands in orgstruct-mode if 
orgstruct-heading-prefix-regexp is non-nil

Christopher



Re: [O] S-M-right problem in orgstruct-mode

2013-03-10 Thread Bastien
Hi Alan and Christopher,

Alan Schmitt  writes:

> even though the cursor is on a structure element. Maybe a more
> information "this function is disabled" would work (if it's possible).
> But as I said, it's a nitpick.

I agree with Alan, let's update the user-error to something more
informative -- Christopher, thanks a lot for the patch!  Feel free
to commit and push when you want.

Best,

-- 
 Bastien



Re: [O] S-M-right problem in orgstruct-mode

2013-03-10 Thread Alan Schmitt
Christopher Schmidt writes:

> Alan Schmitt  writes:
>> Looking at it there seems to be occurrences of '++' that are a bit
>> strange. Was it garbled when attached?
>
> Ooops, I forgot to finalise my merge.

It's looking good, thanks. One small nitpick: when a key is disabled,
the message is

orgstruct-error: This key has no function outside structure elements

even though the cursor is on a structure element. Maybe a more
information "this function is disabled" would work (if it's possible).
But as I said, it's a nitpick.

Thanks again,

Alan



Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Christopher Schmidt
Alan Schmitt  writes:
> Looking at it there seems to be occurrences of '++' that are a bit
> strange. Was it garbled when attached?

Ooops, I forgot to finalise my merge.
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8658,7 +8658,7 @@ If WITH-CASE is non-nil, the sorting will be case-sensitive."
 ;; command.  There might be problems if any of the keys is otherwise
 ;; used as a prefix key.
 
-(defcustom orgstruct-heading-prefix-regexp ""
+(defcustom orgstruct-heading-prefix-regexp nil
   "Regexp that matches the custom prefix of Org headlines in
 orgstruct(++)-mode."
   :group 'org
@@ -8743,72 +8743,80 @@ buffer.  It will also recognize item context in multiline items."
 
 (defun orgstruct-setup ()
   "Setup orgstruct keymap."
-  (dolist (f
-   '("org-meta"
- "org-shift"
- "org-shiftmeta"
- org-shifttab
- org-backward-element
- org-backward-heading-same-level
- org-ctrl-c-ret
-	 org-ctrl-c-minus
-	 org-ctrl-c-star
- org-cycle
- org-forward-heading-same-level
- org-insert-heading
- org-insert-heading-respect-content
- org-kill-note-or-show-branches
- org-mark-subtree
- org-narrow-to-subtree
- org-promote-subtree
- org-reveal
- org-show-subtree
- org-sort
- org-up-element
- outline-demote
- outline-next-visible-heading
- outline-previous-visible-heading
- outline-promote
- outline-up-heading
- show-children))
-(dolist (f (if (stringp f)
-   (let ((flist))
- (dolist (postfix
-  '("-return" "tab" "left" "right" "up" "down")
-  flist)
-   (let ((f (intern (concat f postfix
- (when (fboundp f)
-   (push f flist)
- (list f)))
-  (dolist (binding (nconc (where-is-internal f org-mode-map)
-  (where-is-internal f outline-mode-map)))
-;; TODO use local-function-key-map
-(dolist (rep '(("" . "TAB")
-   ("" . "RET")
-   ("" . "ESC")
-   ("" . "DEL")))
-  (setq binding (read-kbd-macro (replace-regexp-in-string
-	 (regexp-quote (car rep))
-	 (cdr rep)
-	 (key-description binding)
-(let ((key (lookup-key orgstruct-mode-map binding)))
-  (when (or (not key) (numberp key))
-	(condition-case nil
-		(org-defkey orgstruct-mode-map
-			binding
-			(orgstruct-make-binding f binding))
-	  (error nil)))
+  (dolist (cell '((org-demote . t)
+		  (org-metaleft . t)
+		  (org-metaright . t)
+		  (org-promote . t)
+		  (org-shiftmetaleft . t)
+		  (org-shiftmetaright . t)
+		  org-backward-element
+		  org-backward-heading-same-level
+		  org-ctrl-c-ret
+		  org-ctrl-c-minus
+		  org-ctrl-c-star
+		  org-cycle
+		  org-forward-heading-same-level
+		  org-insert-heading
+		  org-insert-heading-respect-content
+		  org-kill-note-or-show-branches
+		  org-mark-subtree
+		  org-meta-return
+		  org-metadown
+		  org-metaup
+		  org-narrow-to-subtree
+		  org-promote-subtree
+		  org-reveal
+		  org-shiftdown
+		  org-shiftleft
+		  org-shiftmetadown
+		  org-shiftmetaup
+		  org-shiftright
+		  org-shifttab
+		  org-shifttab
+		  org-shiftup
+		  org-show-subtree
+		  org-sort
+		  org-up-element
+		  outline-demote
+		  outline-next-visible-heading
+		  outline-previous-visible-heading
+		  outline-promote
+		  outline-up-heading
+		  show-children))
+(let ((f (or (car-safe cell) cell))
+	  (disable-when-heading-prefix (cdr-safe cell)))
+  (when (fboundp f)
+	(dolist (binding (nconc (where-is-internal f org-mode-map)
+(where-is-internal f outline-mode-map)))
+	  ;; TODO use local-function-key-map
+	  (dolist (rep '(("" . "TAB")
+			 ("" . "RET")
+			 ("" . "ESC")
+			 ("" . "DEL")))
+	(setq binding (read-kbd-macro (replace-regexp-in-string
+	   (regexp-quote (car rep))
+	   (cdr rep)
+	   (key-description binding)
+	  (let ((key (lookup-key orgstruct-mode-map binding)))
+	(when (or (not key) (numberp key))
+	  (condition-case nil
+		  (org-defkey orgstruct-mode-map
+			  binding
+			  (orgstruct-make-binding f binding disable-when-heading-prefix))
+		(error nil
   (run-hooks 'orgstruct-setup-hook))
 
-(defun orgstruct-make-binding (fun key)
+(defun orgstruct-make-binding (fun key disable-when-heading-prefix)
   "Create a function for binding in the structure minor mode.
 FUN is the command to call inside a table.  KEY is the key that
-should be checked in for a command to execute outside of tables."
+should be checked in for a command to execute outside of tables.
+Non-nil DISABLE-WHEN-HEADING-PREFIX means to disable the command
+if `orgstruc

Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Alan Schmitt
Christopher Schmidt writes:

> Alan, here is patch for master that should solve the issue.  It disables
> org-{pr,de}mote and org-{,shift}meta{left,right} in orgstruct-mode iff
> orgstruct-heading-prefix-regexp is non-nil.  Could you please give it a
> try and tell us what you think?

Thanks a lot. Unfortunately I could not apply the patch:

~/projets/org-mode(master ✗) git apply --stat ~/Documents/Inbox/2.part 
fatal: unrecognized input

Looking at it there seems to be occurrences of '++' that are a bit
strange. Was it garbled when attached?

Alan



Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Christopher Schmidt
Bastien  writes:
> Christopher Schmidt  writes:
>> ( In the long term this should be fixed properly.  Considering that
>>   point is already on an actual headline, Org just needs to add or
>>   remove a star.  This should not be too hard with
>>   org-heading-regexp. )
>
> Beware that there are *many* commands conditionally called by
> org-metaright, org-metaleft, etc.: org-do-demote, org-do-promote and
> the like.
>
> It would be too much to make all these commands take the value of
> `orgstruct-heading-prefix-regexp' into account, even if we end up
> using a macro `org-with-heading-prefix-regexp' and calling these
> commands from within the macro.  Perhaps accepting some limitations
> will be the right thing, not sure.

That is not necessary.  The hijacking command already makes sure
org-heading-regexp takes orgstruct-heading-prefix-regexp into account.
Nonetheless It is still a lot of work.

Alan, here is patch for master that should solve the issue.  It disables
org-{pr,de}mote and org-{,shift}meta{left,right} in orgstruct-mode iff
orgstruct-heading-prefix-regexp is non-nil.  Could you please give it a
try and tell us what you think?
diff --cc lisp/org.el
index 811506a,a7670dc..000
--- a/lisp/org.el
+++ b/lisp/org.el
@@@ -8743,72 -8695,78 +8743,80 @@@ buffer.  It will also recognize item co
  
  (defun orgstruct-setup ()
"Setup orgstruct keymap."
-   (dolist (f
-'("org-meta"
-  "org-shift"
-  "org-shiftmeta"
-  org-shifttab
-  org-backward-element
-  org-backward-heading-same-level
-  org-ctrl-c-ret
- 	 org-ctrl-c-minus
- 	 org-ctrl-c-star
-  org-cycle
-  org-forward-heading-same-level
-  org-insert-heading
-  org-insert-heading-respect-content
-  org-kill-note-or-show-branches
-  org-mark-subtree
-  org-narrow-to-subtree
-  org-promote-subtree
-  org-reveal
-  org-show-subtree
-  org-sort
-  org-up-element
-  outline-demote
-  outline-next-visible-heading
-  outline-previous-visible-heading
-  outline-promote
-  outline-up-heading
-  show-children))
- (dolist (f (if (stringp f)
-(let ((flist))
-  (dolist (postfix
-   '("-return" "tab" "left" "right" "up" "down")
-   flist)
-(let ((f (intern (concat f postfix
-  (when (fboundp f)
-(push f flist)
-  (list f)))
-   (dolist (binding (nconc (where-is-internal f org-mode-map)
-   (where-is-internal f outline-mode-map)))
- ;; TODO use local-function-key-map
- (dolist (rep '(("" . "TAB")
-("" . "RET")
-("" . "ESC")
-("" . "DEL")))
-   (setq binding (read-kbd-macro (replace-regexp-in-string
- 	 (regexp-quote (car rep))
- 	 (cdr rep)
- 	 (key-description binding)
- (let ((key (lookup-key orgstruct-mode-map binding)))
-   (when (or (not key) (numberp key))
- 	(condition-case nil
- 		(org-defkey orgstruct-mode-map
- 			binding
- 			(orgstruct-make-binding f binding))
- 	  (error nil)))
+   (dolist (cell '((org-demote . t)
+ 		  (org-metaleft . t)
+ 		  (org-metaright . t)
+ 		  (org-promote . t)
+ 		  (org-shiftmetaleft . t)
+ 		  (org-shiftmetaright . t)
+ 		  org-backward-element
+ 		  org-backward-heading-same-level
+ 		  org-ctrl-c-ret
++		  org-ctrl-c-minus
++		  org-ctrl-c-star
+ 		  org-cycle
+ 		  org-forward-heading-same-level
+ 		  org-insert-heading
+ 		  org-insert-heading-respect-content
+ 		  org-kill-note-or-show-branches
+ 		  org-mark-subtree
+ 		  org-meta-return
+ 		  org-metadown
+ 		  org-metaup
+ 		  org-narrow-to-subtree
+ 		  org-promote-subtree
+ 		  org-reveal
+ 		  org-shiftdown
+ 		  org-shiftleft
+ 		  org-shiftmetadown
+ 		  org-shiftmetaup
+ 		  org-shiftright
+ 		  org-shifttab
+ 		  org-shifttab
+ 		  org-shiftup
+ 		  org-show-subtree
+ 		  org-sort
+ 		  org-up-element
+ 		  outline-demote
+ 		  outline-next-visible-heading
+ 		  outline-previous-visible-heading
+ 		  outline-promote
+ 		  outline-up-heading
+ 		  show-children))
+ (let ((f (or (car-safe cell) cell))
+ 	  (disable-when-heading-prefix (cdr-safe cell)))
+   (when (fboundp f)
+ 	(dolist (binding (nconc (where-is-internal f org-mode-map)
+ (where-is-internal f outline-mode-map)))
+ 	  ;; TODO use local-function-key-map
+ 	  (dolist (rep '(("" . "TAB")
+ 			 ("" . "RET")
+ 			 ("" . "ESC")
+ 			 ("" . "DEL")))
+ 	(setq binding (read-kbd-macro (replace-regexp-in-string
+ 	   (regexp-quote (car rep))
+ 	   (cdr rep)
+ 	   (key-description binding)
+ 	  (l

Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Bastien
Hi Christopher,

Christopher Schmidt  writes:

> I agree.  I will come up with a patch ASAP.

Thanks!

> ( In the long term this should be fixed properly.  Considering that
>   point is already on an actual headline, Org just needs to add or
>   remove a star.  This should not be too hard with org-heading-regexp. )

Beware that there are *many* commands conditionally called by
org-metaright, org-metaleft, etc.: org-do-demote, org-do-promote and
the like.

It would be too much to make all these commands take the value of
`orgstruct-heading-prefix-regexp' into account, even if we end up
using a macro `org-with-heading-prefix-regexp' and calling these
commands from within the macro.  Perhaps accepting some limitations
will be the right thing, not sure.

Best,

-- 
 Bastien



Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Christopher Schmidt
Bastien  writes:
> Alan Schmitt  writes:
>
>> and do a shift-meta-right on the second line, I get:
>>
>> #+BEGIN_SRC emacs-lisp
>> ;;; * Test 1
>> ** Test2
>> #+END_SRC
>
> I confirm this issue.
>
> The easiest thing to do is to prevent some commands to run when
> `orgstruct-mode' is on and `orgstruct-heading-prefix-regexp' is
> non-nil.

I agree.  I will come up with a patch ASAP.

( In the long term this should be fixed properly.  Considering that
  point is already on an actual headline, Org just needs to add or
  remove a star.  This should not be too hard with org-heading-regexp. )

Christopher



Re: [O] S-M-right problem in orgstruct-mode

2013-03-09 Thread Bastien
Hi Alan,

Alan Schmitt  writes:

> and do a shift-meta-right on the second line, I get:
>
> #+BEGIN_SRC emacs-lisp
> ;;; * Test 1
> ** Test2
> #+END_SRC

I confirm this issue.

The easiest thing to do is to prevent some commands to run when
`orgstruct-mode' is on and `orgstruct-heading-prefix-regexp' is
non-nil.

Making those commands to work properly would be nice but I don't
think it can be easy enough to implement.

Christopher, what do you think?

-- 
 Bastien



[O] S-M-right problem in orgstruct-mode

2013-03-08 Thread Alan Schmitt
Hello,

I'm using a recently pulled orgmode from master.

I have the following in an emacs-lisp buffer:

#+BEGIN_SRC emacs-lisp
;; Local Variables:
;; eval: (orgstruct-mode 1)
;; orgstruct-heading-prefix-regexp: ";;; "
;; End:
#+END_SRC

With such local variables, if I start with:

#+BEGIN_SRC emacs-lisp
;;; * Test 1
;;; * Test2
#+END_SRC

and do a shift-meta-right on the second line, I get:

#+BEGIN_SRC emacs-lisp
;;; * Test 1
** Test2
#+END_SRC

I also see the following appear in the *Messages* folder:

#+BEGIN_SRC emacs-lisp
org-get-tags-string: Not on a heading
#+END_SRC

Is this a (known) bug?

Thanks,

Alan



[O] S-M-right problem in orgstruct-mode

2013-03-08 Thread Alan Schmitt
Hello,

I'm using a recently pulled orgmode from master.

I have the following in an emacs-lisp buffer:

#+BEGIN_SRC emacs-lisp
;; Local Variables:
;; eval: (orgstruct-mode 1)
;; orgstruct-heading-prefix-regexp: ";;; "
;; End:
#+END_SRC

With such local variables, if I start with:

#+BEGIN_SRC emacs-lisp
;;; * Test 1
;;; * Test2
#+END_SRC

and do a shift-meta-right on the second line, I get:

#+BEGIN_SRC emacs-lisp
;;; * Test 1
** Test2
#+END_SRC

I also see the following appear in the *Messages* folder:

#+BEGIN_SRC emacs-lisp
org-get-tags-string: Not on a heading
#+END_SRC

Is this a (known) bug?

Thanks,

Alan