Quellcode durchsuchen

Shift-selection: More tweaking

I have changed my mind and turned off shift-selection support again by
default, because it causes confusing behavior, sometimes calling an Org
command and sometimes doing shift selection.  The default behavior is
now:

- in special contexts, execute Org commands

- outside special contexts, create an error that will point users to
  configure the variable `org-support-shift-select'.  Hopefully that
  will make them read the docstring and then decide for themselves
  what to do.
Carsten Dominik vor 16 Jahren
Ursprung
Commit
f0899954a3
3 geänderte Dateien mit 78 neuen und 61 gelöschten Zeilen
  1. 7 5
      doc/org.texi
  2. 5 0
      lisp/ChangeLog
  3. 66 56
      lisp/org.el

+ 7 - 5
doc/org.texi

@@ -3194,13 +3194,15 @@ keyword or using completion, you may also apply the following commands:
 @table @kbd
 @kindex C-S-@key{right}
 @kindex C-S-@key{left}
-@item C-S-@key{right}
+@kindex C-u C-u C-c C-t
+@item C-u C-u C-c C-t
+@itemx C-S-@key{right}
 @itemx C-S-@key{left}
 These keys jump from one TODO subset to the next.  In the above example,
-@kbd{C-S-@key{right}} would jump from @code{TODO} or @code{DONE} to
-@code{REPORT}, and any of the words in the second row to @code{CANCELED}.
-Note that this key binding conflicts with @code{shift-selection-mode}
-(@pxref{Conflicts}).
+@kbd{C-u C-u C-c C-t} or @kbd{C-S-@key{right}} would jump from @code{TODO} or
+@code{DONE} to @code{REPORT}, and any of the words in the second row to
+@code{CANCELED}.  Note that the @kbd{C-S-} key binding conflict with
+@code{shift-selection-mode} (@pxref{Conflicts}).
 @kindex S-@key{right}
 @kindex S-@key{left}
 @item S-@key{right}

+ 5 - 0
lisp/ChangeLog

@@ -1,3 +1,8 @@
+2009-01-27  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-shiftselect-error, org-call-for-shift-select): New
+	functions.
+
 2009-01-26  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-support-shift-select): New option.

+ 66 - 56
lisp/org.el

@@ -199,8 +199,7 @@ to add the symbol `xyz', and the package must have a call to
 	(const :tag "C  sqlinsert:         Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert)
 	(repeat :tag "External packages" :inline t (symbol :tag "Package"))))
 
-(defcustom org-support-shift-select
-  (and (boundp 'shift-select-mode) shift-select-mode t)
+(defcustom org-support-shift-select nil
   "Non-nil means, make shift-cursor commands select text when possible.
 
 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
@@ -210,30 +209,34 @@ enough to compete with shift selection.  Org tries to balance these needs
 by supporting `shift-select-mode' outside these special contexts, under
 control of this variable.
 
+The default of this variable is nil, to avoid confusing behavior.
 When this variable is t and the cursor is not in a special context,
 Org-mode will support shift-selection for making and enlarging regions.
 
-Shift-cursor keys have special meanings at the following locations:
-- on a headline (changing TODO state and priority)
-- on a plain list item bullet (cycling the bullet type)
-- on a time stamp (changing the time)
+Shift-cursor keys then still have special meanings at the following
+locations:
+- on a headline, changing TODO state (left/right) and priority (up/down)
+- on a time stamp, changing the time
+- in a property definition line, switching between allowed values
 - in the BEGIN line of a clock table (changing the time block).
 
-If you set this variable to the symbol `even-in-headlines', then the
-keys will not change TODO states and priorities in headlines, to
-make shift selection work there as well.  This is not really a problem,
-because there are alternative commands `C-c C-t' and `C-c ,' to change
-TODO state and priority.
+If you set this variable to the symbol `always', then the keys
+will not be special in headlines and property lines, to make shift
+selection work there as well.  If this is what you want, you can use the
+following alternative commands: `C-c C-t' and `C-c ,' to change TODO
+state and priority, `C-u C-u C-c C-t' can be used to switch TODO sets,
+and properties can be edited by hand or in column view.
 
-However, when the cursor is on a timestamp, headline or not, shift-cursor
-commands will still edit the time stamp - this is just too good to give up.
+However, when the cursor is on a timestamp, shift-cursor commands
+will still edit the time stamp - this is just too good to give up.
 
-XEmacs user should have this variable set to nil."
+XEmacs user should have this variable set to nil, because shift-select-mode
+is Emacs 23 only."
   :group 'org
   :type '(choice
 	  (const :tag "Not at all" nil)
 	  (const :tag "When context allows" t)
-	  (const :tag "Even in headlines" even-in-headlines)))
+	  (const :tag "Everywhere except timestamps" always)))
 
 (defgroup org-startup nil
   "Options concerning startup of Org-mode."
@@ -8309,6 +8312,7 @@ DONE are present, add TODO at the beginning of the heading.
 
 With C-u prefix arg, use completion to determine the new state.
 With numeric prefix arg, switch to that state.
+With a double C-u prefix, switch to the next set of TODO keywords (nextset).
 
 For calling through lisp, arg is also interpreted in the following way:
 'none             -> empty state
@@ -8319,6 +8323,7 @@ For calling through lisp, arg is also interpreted in the following way:
 \"WAITING\"         -> switch to the specified keyword, but only if it
                      really is a member of `org-todo-keywords'."
   (interactive "P")
+  (if (equal arg '(16)) (setq arg 'nextset))
   (save-excursion
     (catch 'exit
       (org-back-to-heading)
@@ -12931,8 +12936,18 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
   (org-defkey org-mode-map "|" 'org-force-self-insert))
 
 (defun org-shiftcursor-error ()
+  "Throw an error, a modified cursor command was applied in wrong context."
+  (error "This command is active in special context like tables, headlines or items"))
+
+(defun org-shiftselect-error ()
   "Throw an error because Shift-Cursor command was applied in wrong context."
-  (error "This command is active in special context like tables, headlines or timestamps"))
+  (if (and (boundp 'shift-select-mode) shift-select-mode)
+      (error "To use shift-selection with Org-mode, customize `org-support-shift-select'.")
+    (error "This command works only in special context like headlines or timestamps.")))
+
+(defun org-call-for-shift-select (cmd)
+  (let ((this-command-keys-shift-translated t))
+    (call-interactively cmd)))
 
 (defun org-shifttab (&optional arg)
   "Global visibility cycling or move to previous table field.
@@ -13052,21 +13067,19 @@ depending on context.  See the individual commands for more information."
   (interactive "P")
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'previous-line)))
+    (org-call-for-shift-select 'previous-line))
    ((org-at-timestamp-p t)
     (call-interactively (if org-edit-timestamp-down-means-later
 			    'org-timestamp-down 'org-timestamp-up)))
-   ((and (not (eq org-support-shift-select 'even-in-headlines))
+   ((and (not (eq org-support-shift-select 'always))
 	 (org-on-heading-p))
     (call-interactively 'org-priority-up))
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-previous-item))
    ((org-clocktable-try-shift 'up arg))
    (org-support-shift-select
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'previous-line)))
-   (t (call-interactively 'org-beginning-of-item) (beginning-of-line 1))))
+    (org-call-for-shift-select 'previous-line))
+   (t (org-shiftselect-error))))
 
 (defun org-shiftdown (&optional arg)
   "Decrease item in timestamp or decrease priority of current headline.
@@ -13075,21 +13088,19 @@ depending on context.  See the individual commands for more information."
   (interactive "P")
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'next-line)))
+    (org-call-for-shift-select 'next-line))
    ((org-at-timestamp-p t)
     (call-interactively (if org-edit-timestamp-down-means-later
 			    'org-timestamp-up 'org-timestamp-down)))
-   ((and (not (eq org-support-shift-select 'even-in-headlines))
+   ((and (not (eq org-support-shift-select 'always))
 	 (org-on-heading-p))
     (call-interactively 'org-priority-down))
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-next-item))
    ((org-clocktable-try-shift 'down arg))
    (org-support-shift-select 
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'next-line)))
-   (t (call-interactively 'org-next-item))))
+    (org-call-for-shift-select 'next-line))
+   (t (org-shiftselect-error))))
 
 (defun org-shiftright (&optional arg)
   "Cycle the thing at point or in the current line, depending on context.
@@ -13103,21 +13114,21 @@ Depending on context, this does one of the following:
   (interactive "P")
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'forward-char)))
+    (org-call-for-shift-select 'forward-char))
    ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
-   ((and (not (eq org-support-shift-select 'even-in-headlines))
+   ((and (not (eq org-support-shift-select 'always))
 	 (org-on-heading-p))
     (org-call-with-arg 'org-todo 'right))
    ((or (and org-support-shift-select (org-at-item-bullet-p))
 	(and (not org-support-shift-select) (org-at-item-p)))
     (org-call-with-arg 'org-cycle-list-bullet nil))
-   ((org-at-property-p) (call-interactively 'org-property-next-allowed-value))
+   ((and (not (eq org-support-shift-select 'always))
+	 (org-at-property-p))
+    (call-interactively 'org-property-next-allowed-value))
    ((org-clocktable-try-shift 'right arg))
    (org-support-shift-select 
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'forward-char)))
-   (t (org-shiftcursor-error))))
+    (org-call-for-shift-select 'forward-char))
+   (t (org-shiftselect-error))))
 
 (defun org-shiftleft (&optional arg)
   "Cycle the thing at point or in the current line, depending on context.
@@ -13131,48 +13142,47 @@ Depending on context, this does one of the following:
   (interactive "P")
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'backward-char)))
+    (org-call-for-shift-select 'backward-char))
    ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
-   ((and (not (eq org-support-shift-select 'even-in-headlines))
+   ((and (not (eq org-support-shift-select 'always))
 	 (org-on-heading-p))
     (org-call-with-arg 'org-todo 'left))
    ((or (and org-support-shift-select (org-at-item-bullet-p))
 	(and (not org-support-shift-select) (org-at-item-p)))
     (org-call-with-arg 'org-cycle-list-bullet 'previous))
-   ((org-at-property-p)
+   ((and (not (eq org-support-shift-select 'always))
+	 (org-at-property-p))
     (call-interactively 'org-property-previous-allowed-value))
    ((org-clocktable-try-shift 'left arg))
    (org-support-shift-select 
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'backward-char)))
-   (t (org-shiftcursor-error))))
+    (org-call-for-shift-select 'backward-char))
+   (t (org-shiftselect-error))))
 
 (defun org-shiftcontrolright ()
   "Switch to next TODO set."
   (interactive)
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'forward-word)))
-   ((org-on-heading-p) (org-call-with-arg 'org-todo 'nextset))
-   (org-support-shift-select 
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'forward-word)))
-   (t (org-shiftcursor-error))))
+    (org-call-for-shift-select 'forward-word))
+   ((and (not (eq org-support-shift-select 'always))
+	 (org-on-heading-p))
+    (org-call-with-arg 'org-todo 'nextset))
+   (org-support-shift-select
+    (org-call-for-shift-select 'forward-word))
+   (t (org-shiftselect-error))))
 
 (defun org-shiftcontrolleft ()
   "Switch to previous TODO set."
   (interactive)
   (cond
    ((and org-support-shift-select (org-region-active-p))
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'backward-word)))
-   ((org-on-heading-p) (org-call-with-arg 'org-todo 'previousset))
-   (org-support-shift-select 
-    (let ((this-command-keys-shift-translated t))
-      (call-interactively 'backward-word)))
-   (t (org-shiftcursor-error))))
+    (org-call-for-shift-select 'backward-word))
+   ((and (not (eq org-support-shift-select 'always))
+	 (org-on-heading-p))
+    (org-call-with-arg 'org-todo 'previousset))
+   (org-support-shift-select
+    (org-call-for-shift-select 'backward-word))
+   (t (org-shiftselect-error))))
 
 (defun org-ctrl-c-ret ()
   "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."