summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien <bzg@gnu.org>2018-04-28 12:09:56 +0200
committerBastien <bzg@gnu.org>2018-04-28 12:09:56 +0200
commit011f1c6181483aca0c0596092a464a049ab507d3 (patch)
tree5e4e7705eef96e46fb7038c3e119bfe1ee1e00de
parentbc37b325801fdc2979272caffefaa74640b1ed0a (diff)
downloadorg-mode-011f1c6181483aca0c0596092a464a049ab507d3.tar.gz
Let `org-agenda-set-restriction-lock' remove restriction at point
* lisp/org-compat.el (org-speedbar-set-agenda-restriction): * lisp/org-agenda.el (org-agenda-set-restriction-lock): If there is an agenda restriction at point, remove it. * doc/org-manual.org: * etc/ORG-NEWS: Document the new feature.
-rw-r--r--doc/org-manual.org29
-rw-r--r--etc/ORG-NEWS7
-rw-r--r--lisp/org-agenda.el79
-rw-r--r--lisp/org-compat.el8
4 files changed, 72 insertions, 51 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org
index ce85f19..4095ff9 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -8338,20 +8338,20 @@ scope for an extended period, use the following commands:
#+kindex: C-c C-x <
#+findex: org-agenda-set-restriction-lock
- Permanently restrict the agenda to the current subtree. When
- called with a prefix argument, or with the cursor before the
- first headline in a file, set the agenda scope to the entire
- file. This restriction remains in effect until removed with
- {{{kbd(C-c C-x >)}}}, or by typing either {{{kbd(<)}}} or
- {{{kbd(>)}}} in the agenda dispatcher. If there is a window
- displaying an agenda view, the new restriction takes effect
- immediately.
+ Restrict the agenda to the current subtree. If there already is
+ a restriction at point, remove it. When called with a universal
+ prefix argument or with the cursor before the first headline in a
+ file, set the agenda scope to the entire file. This restriction
+ remains in effect until removed with {{{kbd(C-c C-x >)}}}, or by typing
+ either {{{kbd(<)}}} or {{{kbd(>)}}} in the agenda dispatcher. If there is a
+ window displaying an agenda view, the new restriction takes
+ effect immediately.
- {{{kbd(C-c C-x >)}}} (~org-agenda-remove-restriction-lock~) ::
#+kindex: C-c C-x >
#+findex: org-agenda-remove-restriction-lock
- Remove the permanent restriction created by {{{kbd(C-c C-x <)}}}.
+ Remove the restriction created by {{{kbd(C-c C-x <)}}}.
#+texinfo: @noindent
When working with =speedbar.el=, you can use the following commands in
@@ -8360,15 +8360,16 @@ the Speedbar frame:
- {{{kbd(<)}}} (~org-speedbar-set-agenda-restriction~) ::
#+findex: org-speedbar-set-agenda-restriction
- Permanently restrict the agenda to the item---either an Org file
- or a subtree in such a file---at the cursor in the Speedbar
- frame. If there is a window displaying an agenda view, the new
- restriction takes effect immediately.
+ Restrict the agenda to the item---either an Org file or a subtree
+ in such a file---at the cursor in the Speedbar frame. If agenda
+ is already restricted there, remove the restriction. If there is
+ a window displaying an agenda view, the new restriction takes
+ effect immediately.
- {{{kbd(>)}}} (~org-agenda-remove-restriction-lock~) ::
#+findex: org-agenda-remove-restriction-lock
- Lift the restriction.
+ Remove the restriction.
** The Agenda Dispatcher
:PROPERTIES:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f23fbcb..776441d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -298,6 +298,13 @@ parameters. See example bellow.
,#+END_SRC
#+END_SRC
+*** ~org-agenda-set-restriction-lock~ toggle agenda restriction at point
+
+You can set an agenda restriction lock with =C-x C-x <= or with =<= at the
+beginning of a headline when using Org speed commands. Now, if there
+is already a restriction at point, hitting =<= again (or =C-x C-x <=) will
+remove it.
+
** New functions
*** ~org-insert-structure-template~
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 67df65a..e30201a 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7124,43 +7124,50 @@ Argument ARG is the prefix argument."
;;;###autoload
(defun org-agenda-set-restriction-lock (&optional type)
- "Set restriction lock for agenda, to current subtree or file.
-Restriction will be the file if TYPE is `file', or if type is the
-universal prefix \\='(4), or if the cursor is before the first headline
-in the file. Otherwise, restriction will be to the current subtree."
+ "Set restriction lock for agenda to current subtree or file.
+When in a restricted subtree, remove it.
+
+The restriction will span over the entire file if TYPE is `file',
+or if type is '(4), or if the cursor is before the first headline
+in the file. Otherwise, only apply the restriction to the current
+subtree."
(interactive "P")
- (org-agenda-remove-restriction-lock 'noupdate)
- (and (equal type '(4)) (setq type 'file))
- (setq type (cond
- (type type)
- ((org-at-heading-p) 'subtree)
- ((condition-case nil (org-back-to-heading t) (error nil))
- 'subtree)
- (t 'file)))
- (if (eq type 'subtree)
- (progn
- (setq org-agenda-restrict (current-buffer))
- (setq org-agenda-overriding-restriction 'subtree)
- (put 'org-agenda-files 'org-restrict
- (list (buffer-file-name (buffer-base-buffer))))
- (org-back-to-heading t)
- (move-overlay org-agenda-restriction-lock-overlay
- (point)
- (if org-agenda-restriction-lock-highlight-subtree
- (save-excursion (org-end-of-subtree t t) (point))
- (point-at-eol)))
- (move-marker org-agenda-restrict-begin (point))
- (move-marker org-agenda-restrict-end
- (save-excursion (org-end-of-subtree t t)))
- (message "Locking agenda restriction to subtree"))
- (put 'org-agenda-files 'org-restrict
- (list (buffer-file-name (buffer-base-buffer))))
- (setq org-agenda-restrict nil)
- (setq org-agenda-overriding-restriction 'file)
- (move-marker org-agenda-restrict-begin nil)
- (move-marker org-agenda-restrict-end nil)
- (message "Locking agenda restriction to file"))
- (setq current-prefix-arg nil)
+ (if (and org-agenda-overriding-restriction
+ (member org-agenda-restriction-lock-overlay
+ (overlays-at (point))))
+ (org-agenda-remove-restriction-lock 'noupdate)
+ (org-agenda-remove-restriction-lock 'noupdate)
+ (and (equal type '(4)) (setq type 'file))
+ (setq type (cond
+ (type type)
+ ((org-at-heading-p) 'subtree)
+ ((condition-case nil (org-back-to-heading t) (error nil))
+ 'subtree)
+ (t 'file)))
+ (if (eq type 'subtree)
+ (progn
+ (setq org-agenda-restrict (current-buffer))
+ (setq org-agenda-overriding-restriction 'subtree)
+ (put 'org-agenda-files 'org-restrict
+ (list (buffer-file-name (buffer-base-buffer))))
+ (org-back-to-heading t)
+ (move-overlay org-agenda-restriction-lock-overlay
+ (point)
+ (if org-agenda-restriction-lock-highlight-subtree
+ (save-excursion (org-end-of-subtree t t) (point))
+ (point-at-eol)))
+ (move-marker org-agenda-restrict-begin (point))
+ (move-marker org-agenda-restrict-end
+ (save-excursion (org-end-of-subtree t t)))
+ (message "Locking agenda restriction to subtree"))
+ (put 'org-agenda-files 'org-restrict
+ (list (buffer-file-name (buffer-base-buffer))))
+ (setq org-agenda-restrict nil)
+ (setq org-agenda-overriding-restriction 'file)
+ (move-marker org-agenda-restrict-begin nil)
+ (move-marker org-agenda-restrict-end nil)
+ (message "Locking agenda restriction to file"))
+ (setq current-prefix-arg nil))
(org-agenda-maybe-redo))
(defun org-agenda-remove-restriction-lock (&optional noupdate)
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index c43160a..01cb0b6 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -688,6 +688,8 @@ This also applied for speedbar access."
(defun org-speedbar-set-agenda-restriction ()
"Restrict future agenda commands to the location at point in speedbar.
+If there is already a restriction lock at the location, remove it.
+
To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
(interactive)
(require 'org-agenda)
@@ -698,7 +700,11 @@ To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
(setq m (get-text-property p 'org-imenu-marker))
(with-current-buffer (marker-buffer m)
(goto-char m)
- (org-agenda-set-restriction-lock 'subtree)))
+ (if (and org-agenda-overriding-restriction
+ (member org-agenda-restriction-lock-overlay
+ (overlays-at (point))))
+ (org-agenda-remove-restriction-lock 'noupdate)
+ (org-agenda-set-restriction-lock 'subtree))))
((setq p (text-property-any (point-at-bol) (point-at-eol)
'speedbar-function 'speedbar-find-file))
(setq tp (previous-single-property-change