Signal error and specify name
- desktop-registry.el (desktop-registry-add-directory): Add an optional NAME parameter which will be asked for (in an interactive context) when the universal argument is used. Print a message if the specified directory has already been registered, signal an error when the (given or generated) name has already been used and only add the directory if neither of these conditions occur. (desktop-registry-add-current-desktop): Add optional NAME parameter which will be asked for (in an interactive context) when the universal argument is used and pass it on to `desktop-registry-add-directory'.
This commit is contained in:
parent
577cc09c74
commit
9e30a9cd87
3 changed files with 40 additions and 19 deletions
7
NEWS
7
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.
|
||||
|
|
18
README.org
18
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
|
||||
|
|
|
@ -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
|
||||
(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)))))
|
||||
(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)
|
||||
|
|
Loading…
Reference in a new issue