aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS7
-rw-r--r--README.org18
-rw-r--r--desktop-registry.el34
3 files changed, 40 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index d8e1851..a38c431 100644
--- a/NEWS
+++ b/NEWS
@@ -12,3 +12,10 @@
- Add =desktop-registry-rename-desktop= command to rename a desktop.
- Specify prompts for each action that wants a desktop selected.
+
+ - Allow specifying of desktop name by using the universal argument.
+
+ - Signal an error when the name for a desktop (either specified or
+ generated) already exists in the registry and show a message when
+ the specified directory has already been registered. Only add the
+ directory if neither of these conditions occur.
diff --git a/README.org b/README.org
index 545cf7b..be611a4 100644
--- a/README.org
+++ b/README.org
@@ -14,13 +14,6 @@ to fix that.
* Usage
- You can use =desktop-registry-prepend-directory= to add a new
- directory to the registry, or
- =desktop-registry-prepend-current-desktop= to add the currently loaded
- desktop to the registry. If you enable
- =desktop-registry-auto-register= it will automatically add new desktop
- files to the registry when you use =desktop-save=.
-
To switch between desktops you can use
=desktop-registry-change-desktop=, this will prompt (with completion)
for the directory you would like to load.
@@ -32,6 +25,17 @@ to fix that.
the name you can use =desktop-registry-rename-desktop= to give it a
new name.
+** Adding new desktops
+
+ You can use =desktop-registry-add-directory= to add a new directory
+ to the registry, or =desktop-registry-add-current-desktop= to add the
+ currently loaded desktop to the registry. With either of these
+ function you can use the universal argument (=C-u=) to specify a
+ name for the desktop as well.
+
+ If you enable =desktop-registry-auto-register= it will automatically
+ add new desktop files to the registry when you use =desktop-save=.
+
** With org-capture-templates
The =desktop-registry-current-desktop= can be used to insert the
diff --git a/desktop-registry.el b/desktop-registry.el
index 5206b96..ba35d16 100644
--- a/desktop-registry.el
+++ b/desktop-registry.el
@@ -60,23 +60,33 @@ Returns DEFAULT when `desktop-dirname' is nil."
default))
;;;###autoload
-(defun desktop-registry-add-directory (dir)
- "Add DIR to the desktop registry."
- (interactive "DDirectory: ")
+(defun desktop-registry-add-directory (dir &optional name)
+ "Add DIR to the desktop registry, possibly using NAME."
+ (interactive (list (read-directory-name "Directory: ")
+ (if (equal current-prefix-arg '(4))
+ (read-string "Name: "))))
(let* ((clean-dir (desktop-registry--canonicalize-dir dir))
- (label (file-name-base clean-dir)))
- (unless (assoc label desktop-registry-registry)
- (customize-save-variable
- 'desktop-registry-registry
- (cons (cons label clean-dir) desktop-registry-registry)))))
+ (label (or name (file-name-base clean-dir))))
+ (cond
+ ((cl-find clean-dir desktop-registry-registry
+ :key 'cdr :test 'equal)
+ (message "Directory %s already registered" clean-dir))
+ ((cl-find label desktop-registry-registry :key 'car :test 'equal)
+ (error "Name %s already used" label))
+ (t (customize-save-variable
+ 'desktop-registry-registry
+ (cons (cons label clean-dir) desktop-registry-registry))))))
;;;###autoload
-(defun desktop-registry-add-current-desktop ()
- "Add the currently opened desktop file to `desktop-registry-registry'."
- (interactive)
+(defun desktop-registry-add-current-desktop (&optional name)
+ "Add the currently opened desktop file to `desktop-registry-registry'.
+
+If NAME is specified use that as the name for the registry entry."
+ (interactive (list (if (equal current-prefix-arg '(4))
+ (read-string "Name: "))))
(unless desktop-dirname
(error "No desktop loaded"))
- (desktop-registry-add-directory desktop-dirname))
+ (desktop-registry-add-directory desktop-dirname name))
(defun desktop-registry--completing-read (&optional prompt
default-current)