From 89d2b34ede2e9d3c5b8294950ac979af3591c816 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 7 Aug 2013 15:55:48 +0200 Subject: [PATCH] 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. --- README.org | 2 +- desktop-registry.el | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.org b/README.org index 04b7a78..545cf7b 100644 --- a/README.org +++ b/README.org @@ -40,5 +40,5 @@ to fix that. #+BEGIN_SRC emacs-lisp (add-to-list 'org-capture-templates '("t" "Task" entry nil - "* TODO %? :%(desktop-registry-current-desktop):")) + "* TODO %? :%(desktop-registry-current-desktop \"\"):")) #+END_SRC diff --git a/desktop-registry.el b/desktop-registry.el index a937b0d..978ef4e 100644 --- a/desktop-registry.el +++ b/desktop-registry.el @@ -49,16 +49,16 @@ (directory-file-name (expand-file-name dir))) ;;;###autoload -(defun desktop-registry-current-desktop () +(defun desktop-registry-current-desktop (&optional default) "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 (let ((canonical (desktop-registry--canonicalize-dir desktop-dirname))) (car (cl-find-if (lambda (d) (equal (cdr d) canonical)) desktop-registry-registry))) - "")) + default)) ;;;###autoload (defun desktop-registry-add-directory (dir) @@ -79,16 +79,19 @@ Returns an empty string when `desktop-dirname' is nil." (error "No desktop loaded")) (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." - (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 - 'desktop-registry--history))) + 'desktop-registry--history default))) ;;;###autoload (defun desktop-registry-remove-desktop (desktop) "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))) (if spec (customize-save-variable @@ -99,7 +102,7 @@ Returns an empty string when `desktop-dirname' is nil." ;;;###autoload (defun desktop-registry-rename-desktop (old new) "Rename DESKTOP." - (interactive (list (desktop-registry--completing-read "Rename: ") + (interactive (list (desktop-registry--completing-read "Rename: " t) (read-string "to: "))) (let ((spec (assoc old desktop-registry-registry))) (if (not spec)