Customisable hash table for directory path mappings
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <Fhvt98-yKAS23oS8ATU5vUTS_xZMWNvm3GqrbJ8zD139jGVPwxi_ixkTX35KkF_ovh_iPXp4cjvznXn8k3xORuldcNDLho1lxwL76sRTFaQ=@protonmail.com> |
----------------------------------------------------------------
A hash table is used to store component keys and associated directory
pathnames. I would like to make the hash table customisable, in
case user wants to change the directory pathnames with "M-x customize".
What should I code for :type? Although I tried to do it, after the
"Show the value of this option" button is clicked, the hash table
entry disappears. The pathnames need also to be checked for validity,
so user can fix them.
(defun lana-normalise-path (pathname)
"Expand Environment Variables and make absolute."
(interactive "sPathname: ")
(let ( (normp (expand-file-name
(substitute-in-file-name pathname))) )
(if (called-interactively-p 'interactive)
(message "Normalised Pathname: %s" normp)
normp)))
(defcustom lana-fpln (make-hash-table :test 'equal)
"Hash table mapping component names to directory pathnames."
:type
:group 'lana
:set (lambda (symbol value)
;; Validate all values are directories
(maphash (lambda (_ dir)
(unless (file-directory-p (lana-normalise-path dir))
(message "Invalid directory: %s" dir)))
value)
(set symbol value)))