Enable use of current desktop as default
When asking the user for a desktop it is now easy to specify that the default should be the current desktop. - desktop-registry.el (desktop-registry-current-desktop): Add optional DEFAULT parameter which specifies the return value when `desktop-dirname' is `nil', instead of previously an empty string. (desktop-registry--completing-read): Add optional DEFAULT-CURRENT parameter which specifies that the current desktop should be the default when asking for a desktop. (desktop-registry-remove-desktop): (desktop-registry-rename-desktop): Use the current desktop as default when asking the user to select a desktop.
This commit is contained in:
parent
e5122febe8
commit
89d2b34ede
2 changed files with 12 additions and 9 deletions
|
@ -40,5 +40,5 @@ to fix that.
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(add-to-list 'org-capture-templates
|
(add-to-list 'org-capture-templates
|
||||||
'("t" "Task" entry nil
|
'("t" "Task" entry nil
|
||||||
"* TODO %? :%(desktop-registry-current-desktop):"))
|
"* TODO %? :%(desktop-registry-current-desktop \"\"):"))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
|
@ -49,16 +49,16 @@
|
||||||
(directory-file-name (expand-file-name dir)))
|
(directory-file-name (expand-file-name dir)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun desktop-registry-current-desktop ()
|
(defun desktop-registry-current-desktop (&optional default)
|
||||||
"Get the name of the currently loaded desktop.
|
"Get the name of the currently loaded desktop.
|
||||||
|
|
||||||
Returns an empty string when `desktop-dirname' is nil."
|
Returns DEFAULT when `desktop-dirname' is nil."
|
||||||
(if desktop-dirname
|
(if desktop-dirname
|
||||||
(let ((canonical
|
(let ((canonical
|
||||||
(desktop-registry--canonicalize-dir desktop-dirname)))
|
(desktop-registry--canonicalize-dir desktop-dirname)))
|
||||||
(car (cl-find-if (lambda (d) (equal (cdr d) canonical))
|
(car (cl-find-if (lambda (d) (equal (cdr d) canonical))
|
||||||
desktop-registry-registry)))
|
desktop-registry-registry)))
|
||||||
""))
|
default))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun desktop-registry-add-directory (dir)
|
(defun desktop-registry-add-directory (dir)
|
||||||
|
@ -79,16 +79,19 @@ Returns an empty string when `desktop-dirname' is nil."
|
||||||
(error "No desktop loaded"))
|
(error "No desktop loaded"))
|
||||||
(desktop-registry-add-directory desktop-dirname))
|
(desktop-registry-add-directory desktop-dirname))
|
||||||
|
|
||||||
(defun desktop-registry--completing-read (&optional prompt)
|
(defun desktop-registry--completing-read (&optional prompt
|
||||||
|
default-current)
|
||||||
"Ask the user to pick a desktop directory."
|
"Ask the user to pick a desktop directory."
|
||||||
(let ((prompt (or prompt "Desktop: ")))
|
(let ((prompt (or prompt "Desktop: "))
|
||||||
|
(default (and default-current
|
||||||
|
(desktop-registry-current-desktop))))
|
||||||
(completing-read prompt desktop-registry-registry nil nil nil
|
(completing-read prompt desktop-registry-registry nil nil nil
|
||||||
'desktop-registry--history)))
|
'desktop-registry--history default)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun desktop-registry-remove-desktop (desktop)
|
(defun desktop-registry-remove-desktop (desktop)
|
||||||
"Remove DESKTOP from the desktop registry."
|
"Remove DESKTOP from the desktop registry."
|
||||||
(interactive (list (desktop-registry--completing-read "Remove: ")))
|
(interactive (list (desktop-registry--completing-read "Remove: " t)))
|
||||||
(let ((spec (assoc desktop desktop-registry-registry)))
|
(let ((spec (assoc desktop desktop-registry-registry)))
|
||||||
(if spec
|
(if spec
|
||||||
(customize-save-variable
|
(customize-save-variable
|
||||||
|
@ -99,7 +102,7 @@ Returns an empty string when `desktop-dirname' is nil."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun desktop-registry-rename-desktop (old new)
|
(defun desktop-registry-rename-desktop (old new)
|
||||||
"Rename DESKTOP."
|
"Rename DESKTOP."
|
||||||
(interactive (list (desktop-registry--completing-read "Rename: ")
|
(interactive (list (desktop-registry--completing-read "Rename: " t)
|
||||||
(read-string "to: ")))
|
(read-string "to: ")))
|
||||||
(let ((spec (assoc old desktop-registry-registry)))
|
(let ((spec (assoc old desktop-registry-registry)))
|
||||||
(if (not spec)
|
(if (not spec)
|
||||||
|
|
Loading…
Reference in a new issue