Change internal name to dreg

Function names starting with `desktop-registry--' were getting a little
long.
This commit is contained in:
Tom Willemse 2014-01-19 17:00:21 +01:00
parent a8ead42994
commit c7cee4fbfb

View file

@ -94,7 +94,7 @@ examples of valid functions."
:group 'desktop-registry :group 'desktop-registry
:type 'function) :type 'function)
(defvar desktop-registry--history nil (defvar dreg--history nil
"History variable for `desktop-registry'.") "History variable for `desktop-registry'.")
(defvar desktop-registry-list-mode-map (defvar desktop-registry-list-mode-map
@ -107,11 +107,11 @@ examples of valid functions."
(define-key map "A" #'desktop-registry-add-current-desktop) (define-key map "A" #'desktop-registry-add-current-desktop)
map)) map))
(defun desktop-registry--canonicalize-dir (dir) (defun dreg--canonicalize-dir (dir)
"Canonicalize DIR for use." "Canonicalize DIR for use."
(directory-file-name (expand-file-name dir))) (directory-file-name (expand-file-name dir)))
(defun desktop-registry--desktop-in-row () (defun dreg--desktop-in-row ()
"If `desktop-registry-list-mode' is active, return the current rowid." "If `desktop-registry-list-mode' is active, return the current rowid."
(and (eql major-mode 'desktop-registry-list-mode) (and (eql major-mode 'desktop-registry-list-mode)
(tabulated-list-get-id))) (tabulated-list-get-id)))
@ -123,8 +123,7 @@ examples of valid functions."
Returns DEFAULT when the variable `desktop-dirname' is nil, which Returns DEFAULT when the variable `desktop-dirname' is nil, which
means there is no desktop currently loaded." means there is no desktop currently loaded."
(if desktop-dirname (if desktop-dirname
(let ((canonical (let ((canonical (dreg--canonicalize-dir desktop-dirname)))
(desktop-registry--canonicalize-dir desktop-dirname)))
(car (cl-find-if (lambda (d) (equal (cdr d) canonical)) (car (cl-find-if (lambda (d) (equal (cdr d) canonical))
desktop-registry-registry))) desktop-registry-registry)))
default)) default))
@ -142,7 +141,7 @@ in `desktop-registry-registry'."
(interactive (list (read-directory-name "Directory: ") (interactive (list (read-directory-name "Directory: ")
(if (equal current-prefix-arg '(4)) (if (equal current-prefix-arg '(4))
(read-string "Name: ")))) (read-string "Name: "))))
(let* ((clean-dir (desktop-registry--canonicalize-dir dir)) (let* ((clean-dir (dreg--canonicalize-dir dir))
(label (or name (file-name-nondirectory clean-dir)))) (label (or name (file-name-nondirectory clean-dir))))
(cond (cond
((cl-find clean-dir desktop-registry-registry ((cl-find clean-dir desktop-registry-registry
@ -171,8 +170,7 @@ entries in `desktop-registry-registry'."
(error "No desktop loaded")) (error "No desktop loaded"))
(desktop-registry-add-directory desktop-dirname name)) (desktop-registry-add-directory desktop-dirname name))
(defun desktop-registry--completing-read (&optional prompt (defun dreg--completing-read (&optional prompt default-current)
default-current)
"Ask the user to pick a desktop directory. "Ask the user to pick a desktop directory.
PROMPT specifies the prompt to use when asking, which defaults to PROMPT specifies the prompt to use when asking, which defaults to
@ -182,20 +180,18 @@ current desktop as default value."
(default (and default-current (default (and default-current
(desktop-registry-current-desktop)))) (desktop-registry-current-desktop))))
(completing-read prompt desktop-registry-registry nil nil nil (completing-read prompt desktop-registry-registry nil nil nil
'desktop-registry--history default))) 'dreg--history default)))
(defun desktop-registry--get-desktop-name (&optional prompt (defun dreg--get-desktop-name (&optional prompt default-current)
default-current)
"Get the name of a desktop. "Get the name of a desktop.
This is done by either looking at the desktop name at point, in This is done by either looking at the desktop name at point, in
case `desktop-registry-list-mode' is active, or asks the user to case `desktop-registry-list-mode' is active, or asks the user to
provide a name with completion. The parameters PROMPT and provide a name with completion. The parameters PROMPT and
DEFAULT-CURRENT are passed directly to DEFAULT-CURRENT are passed directly to `dreg--completing-read'
`desktop-registry--completing-read' when no desktop is found at when no desktop is found at point."
point." (or (dreg--desktop-in-row)
(or (desktop-registry--desktop-in-row) (dreg--completing-read prompt default-current)))
(desktop-registry--completing-read prompt default-current)))
;;;###autoload ;;;###autoload
(defun desktop-registry-remove-desktop (desktop) (defun desktop-registry-remove-desktop (desktop)
@ -205,7 +201,7 @@ If this command is called interactively DESKTOP will be inferred
from the location of the cursor when viewing the desktop list, or from the location of the cursor when viewing the desktop list, or
will be asked of the user (with completion) when the desktop list will be asked of the user (with completion) when the desktop list
is not currently shown." is not currently shown."
(interactive (list (desktop-registry--get-desktop-name "Remove: " t))) (interactive (list (dreg--get-desktop-name "Remove: " t)))
(let ((spec (assoc desktop desktop-registry-registry))) (let ((spec (assoc desktop desktop-registry-registry)))
(if spec (if spec
(customize-save-variable (customize-save-variable
@ -221,7 +217,7 @@ If this command is called interactively OLD will be inferred from
the location of the cursor when viewing the desktop list, or will the location of the cursor when viewing the desktop list, or will
be asked of the user (with completion) when the desktop list is be asked of the user (with completion) when the desktop list is
not currently shown. NEW is always asked of the user." not currently shown. NEW is always asked of the user."
(interactive (list (desktop-registry--get-desktop-name "Rename: " t) (interactive (list (dreg--get-desktop-name "Rename: " t)
(read-string "to: "))) (read-string "to: ")))
(let ((spec (assoc old desktop-registry-registry))) (let ((spec (assoc old desktop-registry-registry)))
(if (not spec) (if (not spec)
@ -241,7 +237,7 @@ is not currently shown.
This function just calls `desktop-change-dir' with the directory This function just calls `desktop-change-dir' with the directory
attached to NAME." attached to NAME."
(interactive (list (desktop-registry--get-desktop-name "Switch to: "))) (interactive (list (dreg--get-desktop-name "Switch to: ")))
(desktop-change-dir (cdr (assoc name desktop-registry-registry)))) (desktop-change-dir (cdr (assoc name desktop-registry-registry))))
;;;###autoload ;;;###autoload
@ -258,7 +254,7 @@ Enabling this global minor mode will add
(remove-hook 'desktop-save-hook (remove-hook 'desktop-save-hook
'desktop-registry-add-current-desktop))) 'desktop-registry-add-current-desktop)))
(defun desktop-registry--prepare-row (data) (defun dreg--prepare-row (data)
"Format a row of DATA for `tabulated-list-entries'." "Format a row of DATA for `tabulated-list-entries'."
(let* ((name (car data)) (let* ((name (car data))
(dir (cdr data)) (dir (cdr data))
@ -266,11 +262,10 @@ Enabling this global minor mode will add
(file-directory-p dir)))) (file-directory-p dir))))
(list name (vector name (if existsp "yes" "no") dir)))) (list name (vector name (if existsp "yes" "no") dir))))
(defun desktop-registry--refresh-list () (defun dreg--refresh-list ()
"Fill `tabulated-list-entries' with registered desktops." "Fill `tabulated-list-entries' with registered desktops."
(setq tabulated-list-entries (setq tabulated-list-entries
(mapcar #'desktop-registry--prepare-row (mapcar #'dreg--prepare-row desktop-registry-registry)))
desktop-registry-registry)))
(define-derived-mode desktop-registry-list-mode tabulated-list-mode (define-derived-mode desktop-registry-list-mode tabulated-list-mode
"Desktop Registry" "Desktop Registry"
@ -282,7 +277,7 @@ Enabling this global minor mode will add
("Exists" 6 nil) ("Exists" 6 nil)
("Location" 0 t)] ("Location" 0 t)]
tabulated-list-sort-key '("Label")) tabulated-list-sort-key '("Label"))
(add-hook 'tabulated-list-revert-hook #'desktop-registry--refresh-list) (add-hook 'tabulated-list-revert-hook #'dreg--refresh-list)
(tabulated-list-init-header)) (tabulated-list-init-header))
;;;###autoload ;;;###autoload
@ -301,7 +296,7 @@ function to use in
(let ((buffer (get-buffer-create "*Desktop Registry*"))) (let ((buffer (get-buffer-create "*Desktop Registry*")))
(with-current-buffer buffer (with-current-buffer buffer
(desktop-registry-list-mode) (desktop-registry-list-mode)
(desktop-registry--refresh-list) (dreg--refresh-list)
(tabulated-list-print)) (tabulated-list-print))
(funcall desktop-registry-list-switch-buffer-function buffer)) (funcall desktop-registry-list-switch-buffer-function buffer))
nil) nil)