Add desktop-registry-current-desktop

* desktop-registry.el (desktop-registry--canonicalize-dir):
  (desktop-registry-current-desktop): New functions.
  (desktop-registry-add-directory): Use
  `desktop-registry--canonicalize-dir' to get the "clean" directory
  name.
This commit is contained in:
Tom Willemse 2013-08-06 17:04:18 +02:00
parent 131cd421c0
commit 395277047e
3 changed files with 31 additions and 1 deletions

3
NEWS
View file

@ -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.

View file

@ -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

View file

@ -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