diff --git a/NEWS b/NEWS index b9ba2f2..18a8ce4 100644 --- a/NEWS +++ b/NEWS @@ -5,3 +5,6 @@ - Add =desktop-registry-remove-desktop= command to remove desktops you no longer (want to) use. + + - Add =desktop-registry-current-desktop= function to get the name of + the currently loaded desktop. diff --git a/README.org b/README.org index aefc2b1..bb2ac62 100644 --- a/README.org +++ b/README.org @@ -27,3 +27,14 @@ to fix that. When you're done with a desktop or want to get rid of a desktop for another reason you can use =desktop-registry-remove-desktop=. + +** With org-capture-templates + + The =desktop-registry-current-desktop= can be used to insert the + currently loaded desktop into an org capture template. + + #+BEGIN_SRC emacs-lisp + (add-to-list 'org-capture-templates + '("t" "Task" entry nil + "* TODO %? :%(desktop-registry-current-desktop):")) + #+END_SRC diff --git a/desktop-registry.el b/desktop-registry.el index c8bc55e..71c8b4b 100644 --- a/desktop-registry.el +++ b/desktop-registry.el @@ -44,11 +44,27 @@ (defvar desktop-registry--history nil "History variable for `desktop-registry'.") +(defun desktop-registry--canonicalize-dir (dir) + "Canonicalize DIR for use." + (directory-file-name (expand-file-name dir))) + +;;;###autoload +(defun desktop-registry-current-desktop () + "Get the name of the currently loaded desktop. + +Returns an empty string 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))) + "")) + ;;;###autoload (defun desktop-registry-add-directory (dir) "Add DIR to the desktop registry." (interactive "DDirectory: ") - (let* ((clean-dir (directory-file-name (expand-file-name dir))) + (let* ((clean-dir (desktop-registry--canonicalize-dir dir)) (label (file-name-base clean-dir))) (unless (assoc label desktop-registry-registry) (customize-save-variable