summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-20 12:58:42 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-20 13:07:46 +0100
commitd378d9ec7ebf3a6f7b7b5e0ef7a264cd5815c022 (patch)
treec349371e256df5871f4b05c633545736fa72e8cb
parent3604f24f956896574fdc30eddfbce2a475b2b8d5 (diff)
downloadorg-mode-d378d9ec7ebf3a6f7b7b5e0ef7a264cd5815c022.tar.gz
Do not hijack keybindings in Calendar mode
* lisp/org-compat.el (org-calendar-to-agenda-key): (org-calendar-insert-diary-entry-key): Moved from "org.el". (org--setup-calendar-bindings): New function. Fixes: Bug#10289
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/org-compat.el49
-rw-r--r--lisp/org.el30
3 files changed, 53 insertions, 31 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aff3725..65580d1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -57,6 +57,11 @@ should become
,#+END_SRC
#+END_SRC
+*** Change ~org-calendar-to-agenda-key~ value
+
+Default value and accepted value types changed. See [[doc:org-calendar-to-agenda-key][docstring]] for
+details.
+
*** Change ~org-structure-template-alist~ value
With the new template expansion mechanism (see
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 4d87777..ce9f8f6 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -25,7 +25,7 @@
;;; Commentary:
;; This file contains code needed for compatibility with older
-;; versions of GNU Emacs.
+;; versions of GNU Emacs and integration with other packages.
;;; Code:
@@ -842,6 +842,53 @@ ELEMENT is the element at point."
"Make the position visible."
(org-bookmark-jump-unhide))))
+;;;; Calendar
+
+(defcustom org-calendar-to-agenda-key 'default
+ "Key to be installed in `calendar-mode-map' for switching to the agenda.
+
+The command `org-calendar-goto-agenda' will be bound to this key.
+
+When set to `default', bind the function to `c', but only if it is
+available in the Calendar keymap. This is the default choice because
+`c' can then be used to switch back and forth between agenda and calendar.
+
+When nil, `org-calendar-goto-agenda' is not bound to any key."
+ :group 'org-agenda
+ :type '(choice
+ (const :tag "Bind to `c' if available" default)
+ (key-sequence :tag "Other binding")
+ (const :tag "No binding" nil))
+ :safe (lambda (v) (or (symbolp v) (stringp v)))
+ :package-version '(Org . "9.2"))
+
+(defcustom org-calendar-insert-diary-entry-key [?i]
+ "The key to be installed in `calendar-mode-map' for adding diary entries.
+This option is irrelevant until `org-agenda-diary-file' has been configured
+to point to an Org file. When that is the case, the command
+`org-agenda-diary-entry' will be bound to the key given here, by default
+`i'. In the calendar, `i' normally adds entries to `diary-file'. So
+if you want to continue doing this, you need to change this to a different
+key."
+ :group 'org-agenda
+ :type 'sexp)
+
+(defun org--setup-calendar-bindings ()
+ "Bind Org functions in Calendar keymap."
+ (pcase org-calendar-to-agenda-key
+ (`nil nil)
+ ((and key (pred stringp))
+ (local-set-key (kbd key) #'org-calendar-goto-agenda))
+ ((guard (not (lookup-key calendar-mode-map "c")))
+ (local-set-key "c" #'org-calendar-goto-agenda))
+ (_ nil))
+ (unless (eq org-agenda-diary-file 'diary-file)
+ (local-set-key org-calendar-insert-diary-entry-key
+ #'org-agenda-diary-entry)))
+
+(eval-after-load "calendar"
+ '(add-hook 'calendar-mode-hook #'org--setup-calendar-bindings))
+
;;;; Saveplace
;; Make sure saveplace shows the location if it was hidden
diff --git a/lisp/org.el b/lisp/org.el
index a9d7f00..a0308e0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3771,25 +3771,6 @@ A nil value means to remove them, after a query, from the list."
:group 'org-agenda
:type 'boolean)
-(defcustom org-calendar-to-agenda-key [?c]
- "The key to be installed in `calendar-mode-map' for switching to the agenda.
-The command `org-calendar-goto-agenda' will be bound to this key. The
-default is the character `c' because then `c' can be used to switch back and
-forth between agenda and calendar."
- :group 'org-agenda
- :type 'sexp)
-
-(defcustom org-calendar-insert-diary-entry-key [?i]
- "The key to be installed in `calendar-mode-map' for adding diary entries.
-This option is irrelevant until `org-agenda-diary-file' has been configured
-to point to an Org file. When that is the case, the command
-`org-agenda-diary-entry' will be bound to the key given here, by default
-`i'. In the calendar, `i' normally adds entries to `diary-file'. So
-if you want to continue doing this, you need to change this to a different
-key."
- :group 'org-agenda
- :type 'sexp)
-
(defcustom org-agenda-diary-file 'diary-file
"File to which to add new entries with the `i' key in agenda and calendar.
When this is the symbol `diary-file', the functionality in the Emacs
@@ -3800,17 +3781,6 @@ points to a file, `org-agenda-diary-entry' will be used instead."
(const :tag "The standard Emacs diary file" diary-file)
(file :tag "Special Org file diary entries")))
-(eval-after-load "calendar"
- '(progn
- (org-defkey calendar-mode-map org-calendar-to-agenda-key
- 'org-calendar-goto-agenda)
- (add-hook 'calendar-mode-hook
- (lambda ()
- (unless (eq org-agenda-diary-file 'diary-file)
- (define-key calendar-mode-map
- org-calendar-insert-diary-entry-key
- 'org-agenda-diary-entry))))))
-
(defgroup org-latex nil
"Options for embedding LaTeX code into Org mode."
:tag "Org LaTeX"