diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index aff372582..65580d116 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 4d87777d1..ce9f8f6d3 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 a9d7f00c4..a0308e0b6 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"