diff options
| author | David Ponce | 2006-03-13 07:49:31 +0000 |
|---|---|---|
| committer | David Ponce | 2006-03-13 07:49:31 +0000 |
| commit | a32703cbe0886570b771095abdeb51d81fa10332 (patch) | |
| tree | 64e149eb95f43191e222b1434c2cf8cd72e48462 | |
| parent | 4f8f072e2e251a3c166710099d4f1971d7b11dd2 (diff) | |
| download | emacs-a32703cbe0886570b771095abdeb51d81fa10332.tar.gz emacs-a32703cbe0886570b771095abdeb51d81fa10332.zip | |
Handle themes across all occurrences of the main
themes sub-directory found in tree-widget-themes-load-path.
(tree-widget-themes-directory, tree-widget-theme): Doc fix.
(tree-widget--locate-sub-directory): Return all occurrences.
(tree-widget-themes-path): New function. Replace
tree-widget-themes-directory, and return a list of directories.
(tree-widget-set-parent-theme)
(tree-widget-lookup-image): Use it.
| -rw-r--r-- | lisp/tree-widget.el | 139 |
1 files changed, 76 insertions, 63 deletions
diff --git a/lisp/tree-widget.el b/lisp/tree-widget.el index b868369fc4a..4588cc78994 100644 --- a/lisp/tree-widget.el +++ b/lisp/tree-widget.el | |||
| @@ -154,8 +154,9 @@ XEmacs.") | |||
| 154 | (defcustom tree-widget-themes-directory "tree-widget" | 154 | (defcustom tree-widget-themes-directory "tree-widget" |
| 155 | "*Name of the directory where to look up for image themes. | 155 | "*Name of the directory where to look up for image themes. |
| 156 | When nil use the directory where the tree-widget library is located. | 156 | When nil use the directory where the tree-widget library is located. |
| 157 | When a relative name is specified, try to locate that sub directory in | 157 | When a relative name is specified, search in all occurrences of that |
| 158 | the locations specified in `tree-widget-themes-load-path'. | 158 | sub directory found in the locations specified in |
| 159 | `tree-widget-themes-load-path'. | ||
| 159 | The default is to use the \"tree-widget\" relative name." | 160 | The default is to use the \"tree-widget\" relative name." |
| 160 | :type '(choice (const :tag "Default" "tree-widget") | 161 | :type '(choice (const :tag "Default" "tree-widget") |
| 161 | (const :tag "With the library" nil) | 162 | (const :tag "With the library" nil) |
| @@ -164,9 +165,9 @@ The default is to use the \"tree-widget\" relative name." | |||
| 164 | 165 | ||
| 165 | (defcustom tree-widget-theme nil | 166 | (defcustom tree-widget-theme nil |
| 166 | "*Name of the theme where to look up for images. | 167 | "*Name of the theme where to look up for images. |
| 167 | It must be a sub directory of the directory specified in variable | 168 | It must be a sub directory in the directories specified in variable |
| 168 | `tree-widget-themes-directory'. The default theme is \"default\". | 169 | `tree-widget-themes-directory'. The default theme is \"default\". |
| 169 | When an image is not found in a theme, it is searched in the default | 170 | When an image is not found in a theme, it is searched in the parent |
| 170 | theme. | 171 | theme. |
| 171 | 172 | ||
| 172 | A complete theme must at least contain images with these file names | 173 | A complete theme must at least contain images with these file names |
| @@ -275,10 +276,15 @@ The default parent theme is the \"default\" theme." | |||
| 275 | (unless (member name (aref tree-widget--theme 0)) | 276 | (unless (member name (aref tree-widget--theme 0)) |
| 276 | (aset tree-widget--theme 0 | 277 | (aset tree-widget--theme 0 |
| 277 | (append (aref tree-widget--theme 0) (list name))) | 278 | (append (aref tree-widget--theme 0) (list name))) |
| 278 | ;; Load the theme setup | 279 | ;; Load the theme setup from the first directory where the theme |
| 279 | (let ((default-directory (tree-widget-themes-directory))) | 280 | ;; is found. |
| 280 | (when default-directory | 281 | (catch 'found |
| 281 | (load (expand-file-name "tree-widget-theme-setup" name) t))))) | 282 | (dolist (dir (tree-widget-themes-path)) |
| 283 | (setq dir (expand-file-name name dir)) | ||
| 284 | (when (file-accessible-directory-p dir) | ||
| 285 | (throw 'found | ||
| 286 | (load (expand-file-name | ||
| 287 | "tree-widget-theme-setup" dir) t))))))) | ||
| 282 | 288 | ||
| 283 | (defun tree-widget-set-theme (&optional name) | 289 | (defun tree-widget-set-theme (&optional name) |
| 284 | "In the current buffer, set the theme to use for images. | 290 | "In the current buffer, set the theme to use for images. |
| @@ -304,54 +310,62 @@ Typically it should contain something like this: | |||
| 304 | (tree-widget-set-parent-theme name) | 310 | (tree-widget-set-parent-theme name) |
| 305 | (tree-widget-set-parent-theme "default"))) | 311 | (tree-widget-set-parent-theme "default"))) |
| 306 | 312 | ||
| 307 | (defun tree-widget--locate-sub-directory (name path) | 313 | (defun tree-widget--locate-sub-directory (name path &optional found) |
| 308 | "Locate the sub-directory NAME in PATH. | 314 | "Locate all occurrences of the sub-directory NAME in PATH. |
| 309 | Return the absolute name of the directory found, or nil if not found." | 315 | Return a list of absolute directory names in reverse order, or nil if |
| 310 | (let (dir elt) | 316 | not found." |
| 311 | (while (and (not dir) (consp path)) | 317 | (condition-case err |
| 312 | (setq elt (condition-case nil (eval (car path)) (error nil)) | 318 | (dolist (elt path) |
| 313 | path (cdr path)) | 319 | (setq elt (eval elt)) |
| 314 | (cond | 320 | (cond |
| 315 | ((stringp elt) | 321 | ((stringp elt) |
| 316 | (setq dir (expand-file-name name elt)) | 322 | (and (file-accessible-directory-p |
| 317 | (or (file-accessible-directory-p dir) | 323 | (setq elt (expand-file-name name elt))) |
| 318 | (setq dir nil))) | 324 | (push elt found))) |
| 319 | ((and elt (not (equal elt (car path)))) | 325 | (elt |
| 320 | (setq dir (tree-widget--locate-sub-directory name elt))))) | 326 | (setq found (tree-widget--locate-sub-directory |
| 321 | dir)) | 327 | name (if (atom elt) (list elt) elt) found))))) |
| 322 | 328 | (error | |
| 323 | (defun tree-widget-themes-directory () | 329 | (message "In tree-widget--locate-sub-directory: %s" |
| 324 | "Locate the directory where to search for a theme. | 330 | (error-message-string err)))) |
| 325 | It is defined in variable `tree-widget-themes-directory'. | 331 | found) |
| 326 | Return the absolute name of the directory found, or nil if the | 332 | |
| 327 | specified directory is not accessible." | 333 | (defun tree-widget-themes-path () |
| 328 | (let ((found (aref tree-widget--theme 1))) | 334 | "Return the path where to search for a theme. |
| 335 | It is specified in variable `tree-widget-themes-directory'. | ||
| 336 | Return a list of absolute directory names, or nil when no directory | ||
| 337 | has been found accessible." | ||
| 338 | (let ((path (aref tree-widget--theme 1))) | ||
| 329 | (cond | 339 | (cond |
| 330 | ;; The directory was not found. | 340 | ;; No directory was found. |
| 331 | ((eq found 'void) | 341 | ((eq path 'void) nil) |
| 332 | (setq found nil)) | 342 | ;; The list of directories is available in the cache. |
| 333 | ;; The directory is available in the cache. | 343 | (path) |
| 334 | (found) | ||
| 335 | ;; Use the directory where this library is located. | 344 | ;; Use the directory where this library is located. |
| 336 | ((null tree-widget-themes-directory) | 345 | ((null tree-widget-themes-directory) |
| 337 | (setq found (locate-library "tree-widget")) | 346 | (when (setq path (locate-library "tree-widget")) |
| 338 | (when found | 347 | (setq path (file-name-directory path)) |
| 339 | (setq found (file-name-directory found)) | 348 | (setq path (and (file-accessible-directory-p path) |
| 340 | (or (file-accessible-directory-p found) | 349 | (list path))) |
| 341 | (setq found nil)))) | 350 | ;; Store the result in the cache for later use. |
| 351 | (aset tree-widget--theme 1 (or path 'void)) | ||
| 352 | path)) | ||
| 342 | ;; Check accessibility of absolute directory name. | 353 | ;; Check accessibility of absolute directory name. |
| 343 | ((file-name-absolute-p tree-widget-themes-directory) | 354 | ((file-name-absolute-p tree-widget-themes-directory) |
| 344 | (setq found (expand-file-name tree-widget-themes-directory)) | 355 | (setq path (expand-file-name tree-widget-themes-directory)) |
| 345 | (or (file-accessible-directory-p found) | 356 | (setq path (and (file-accessible-directory-p path) |
| 346 | (setq found nil))) | 357 | (list path))) |
| 358 | ;; Store the result in the cache for later use. | ||
| 359 | (aset tree-widget--theme 1 (or path 'void)) | ||
| 360 | path) | ||
| 347 | ;; Locate a sub-directory in `tree-widget-themes-load-path'. | 361 | ;; Locate a sub-directory in `tree-widget-themes-load-path'. |
| 348 | (t | 362 | (t |
| 349 | (setq found (tree-widget--locate-sub-directory | 363 | (setq path (nreverse (tree-widget--locate-sub-directory |
| 350 | tree-widget-themes-directory | 364 | tree-widget-themes-directory |
| 351 | tree-widget-themes-load-path)))) | 365 | tree-widget-themes-load-path))) |
| 352 | ;; Store the result in the cache for later use. | 366 | ;; Store the result in the cache for later use. |
| 353 | (aset tree-widget--theme 1 (or found 'void)) | 367 | (aset tree-widget--theme 1 (or path 'void)) |
| 354 | found)) | 368 | path)))) |
| 355 | 369 | ||
| 356 | (defconst tree-widget--cursors | 370 | (defconst tree-widget--cursors |
| 357 | ;; Pointer shapes when the mouse pointer is over inactive | 371 | ;; Pointer shapes when the mouse pointer is over inactive |
| @@ -391,20 +405,19 @@ Search first in current theme, then in parent themes (see also the | |||
| 391 | function `tree-widget-set-parent-theme'). | 405 | function `tree-widget-set-parent-theme'). |
| 392 | Return the first image found having a supported format, or nil if not | 406 | Return the first image found having a supported format, or nil if not |
| 393 | found." | 407 | found." |
| 394 | (let ((default-directory (tree-widget-themes-directory)) file) | 408 | (catch 'found |
| 395 | (when default-directory | 409 | (dolist (default-directory (tree-widget-themes-path)) |
| 396 | (catch 'found | 410 | (dolist (dir (aref tree-widget--theme 0)) |
| 397 | (dolist (dir (aref tree-widget--theme 0)) | 411 | (dolist (fmt (tree-widget-image-formats)) |
| 398 | (dolist (fmt (tree-widget-image-formats)) | 412 | (dolist (ext (cdr fmt)) |
| 399 | (dolist (ext (cdr fmt)) | 413 | (setq file (expand-file-name (concat name ext) dir)) |
| 400 | (setq file (expand-file-name (concat name ext) dir)) | 414 | (and (file-readable-p file) |
| 401 | (and (file-readable-p file) | 415 | (file-regular-p file) |
| 402 | (file-regular-p file) | 416 | (throw 'found |
| 403 | (throw 'found | 417 | (tree-widget-create-image |
| 404 | (tree-widget-create-image | 418 | (car fmt) file |
| 405 | (car fmt) file | 419 | (tree-widget-image-properties name)))))))) |
| 406 | (tree-widget-image-properties name))))))) | 420 | nil)) |
| 407 | nil)))) | ||
| 408 | 421 | ||
| 409 | (defun tree-widget-find-image (name) | 422 | (defun tree-widget-find-image (name) |
| 410 | "Find the image with NAME in current theme. | 423 | "Find the image with NAME in current theme. |