Mercurial > hg > xemacs-beta
annotate lisp/cus-dep.el @ 5818:15b0715c204d
Avoid passing patterns to with charset property to FcNameUnparse.
Prevents crash reported by Raymond Toy.
| author | Stephen J. Turnbull <stephen@xemacs.org> |
|---|---|
| date | Sat, 18 Oct 2014 21:20:42 +0900 |
| parents | 308d34e9f07d |
| children |
| rev | line source |
|---|---|
| 428 | 1 ;;; cus-dep.el --- Find customization dependencies. |
| 2 ;; | |
| 3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
| 1298 | 4 ;; Copyright (C) 2003 Ben Wing. |
| 428 | 5 ;; |
| 6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>, then | |
| 7 ;; Richard Stallman <rms@gnu.ai.mit.edu>, then | |
| 8 ;; Hrvoje Niksic <hniksic@xemacs.org> (rewritten for XEmacs) | |
| 9 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org> | |
| 10 ;; Keywords: internal | |
| 11 | |
| 12 ;; This file is part of XEmacs. | |
| 13 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
14 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
15 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
16 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
17 ;; option) any later version. |
| 428 | 18 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
19 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
20 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
21 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
22 ;; for more details. |
| 428 | 23 |
| 24 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2544
diff
changeset
|
25 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 428 | 26 |
| 27 ;;; Synched up with: Not synched with FSF. | |
| 28 | |
| 29 | |
| 30 ;;; Commentary: | |
| 31 | |
| 32 ;; This file generates the custom-load files, loaded by cus-load.el. | |
| 442 | 33 ;; Entry points are `Custom-make-dependencies' and |
| 34 ;; `Custom-make-one-dependency'. | |
| 428 | 35 |
| 36 ;; It works by scanning all the `.el' files in a directory, and | |
| 37 ;; evaluates any `defcustom', `defgroup', or `defface' expression that | |
| 38 ;; it finds. The symbol changed by this expression is stored to a | |
| 39 ;; hash table as the hash key, file name being the value. | |
| 40 | |
| 41 ;; After all the files have been examined, custom-loads.el is | |
| 42 ;; generated by mapping all the atoms, and seeing if any of them | |
| 43 ;; contains a `custom-group' property. This property is a list whose | |
| 44 ;; each element's car is the "child" group symbol. If that property | |
| 45 ;; is in the hash-table, the file name will be looked up from the | |
| 46 ;; hash-table, and added to cusload-file. Because the hash-table is | |
| 47 ;; cleared whenever we process a new directory, we cannot get confused | |
| 48 ;; by custom-loads from another directory, or from a previous | |
| 49 ;; installation. This is also why it is perfectly safe to have old | |
| 50 ;; custom-loads around, and have them loaded by `cus-load.el' (as | |
| 51 ;; invoked by `cus-edit.el'). | |
| 52 | |
| 53 ;; A trivial, but useful optimization is that if cusload-file exists, | |
| 54 ;; and no .el files in the directory are newer than cusload-file, it | |
| 55 ;; will not be generated. This means that the directories where | |
| 56 ;; nothing has changed will be skipped. | |
| 57 | |
| 58 ;; The `custom-add-loads' function, used by files generated by | |
| 59 ;; `Custom-make-dependencies', updates the symbol's `custom-loads' | |
| 60 ;; property (a list of strings) with a new list of strings, | |
| 61 ;; eliminating the duplicates. Additionally, it adds the symbol to | |
| 62 ;; `custom-group-hash-table'. It is defined in `cus-load.el'. | |
| 63 | |
| 64 ;; Example: | |
| 65 | |
| 66 ;; (custom-add-loads 'foo 'custom-loads '("bar" "baz")) | |
| 67 ;; (get 'foo 'custom-loads) | |
| 68 ;; => ("bar" "baz") | |
| 69 ;; | |
| 70 ;; (custom-add-loads 'foo 'custom-loads '("hmph" "baz" "quz")) | |
| 71 ;; (get 'foo 'custom-loads) | |
| 72 ;; => ("bar" "baz" "hmph" "qux") | |
| 73 | |
| 74 ;; Obviously, this allows correct incremental loading of custom-load | |
| 75 ;; files. This is not necessary under FSF (they simply use `put'), | |
| 76 ;; since they have only one file with custom dependencies. With the | |
| 77 ;; advent of packages, we cannot afford the same luxury. | |
| 1298 | 78 ;; |
| 79 ;; Feb 2003: Added code to speed up building by caching the values we've | |
| 80 ;; constructed, and using them instead of scanning a file when custom-load | |
| 81 ;; is up-to-date w.r.t. the file. Also use `message' not `princ' to print | |
| 82 ;; out messages so nl's are correctly inserted when necessary. --ben | |
| 428 | 83 |
| 84 | |
| 85 ;;; Code: | |
| 86 | |
| 87 (require 'cl) | |
| 88 (require 'widget) | |
| 89 (require 'cus-face) | |
| 90 | |
| 1244 | 91 ;; #### This and the autoloads file naming variables belong in a separate |
| 92 ;; file to be required here. | |
| 93 ;; #### Compare this with the autoloads handling. | |
| 428 | 94 ;; Don't change this, unless you plan to change the code in |
| 95 ;; cus-start.el, too. | |
| 96 (defconst cusload-base-file "custom-load.el") | |
| 1298 | 97 (defconst cusload-hash-table-marker ";old-cus-dep-hash: ") |
| 428 | 98 |
| 99 ;; Be very careful when changing this function. It looks easy to | |
| 100 ;; understand, but is in fact very easy to break. Be sure to read and | |
| 101 ;; understand the commentary above! | |
| 102 | |
| 442 | 103 (defun Custom-make-dependencies-1 (subdirs) |
| 428 | 104 (setq subdirs (mapcar #'expand-file-name subdirs)) |
| 105 (with-temp-buffer | |
| 106 (let ((enable-local-eval nil) | |
| 1298 | 107 (hash (make-hash-table :test 'eq)) |
| 108 (hash-cache (make-hash-table :test 'equal)) | |
| 109 old-hash) | |
| 428 | 110 (dolist (dir subdirs) |
| 1298 | 111 (message "Processing %s\n" dir) |
| 428 | 112 (let ((cusload-file (expand-file-name cusload-base-file dir)) |
| 113 (files (directory-files dir t "\\`[^=].*\\.el\\'"))) | |
| 114 ;; A trivial optimization: if no file in the directory is | |
| 115 ;; newer than custom-load.el, no need to do anything! | |
| 116 (if (and (file-exists-p cusload-file) | |
| 117 (dolist (file files t) | |
| 118 (when (file-newer-than-file-p file cusload-file) | |
| 119 (return nil)))) | |
| 1298 | 120 (message "(No changes need to be written)") |
| 121 (when (file-exists-p cusload-file) | |
| 122 (let ((buf (find-file-noselect cusload-file))) | |
| 123 (with-current-buffer buf | |
| 124 (goto-char (point-min)) | |
| 125 (when (search-forward cusload-hash-table-marker nil t) | |
| 126 (setq old-hash (read buf)))) | |
| 127 (kill-buffer buf))) | |
| 428 | 128 ;; Process directory |
| 129 (dolist (file files) | |
| 1298 | 130 (let ((old-cache (if (hash-table-p old-hash) |
| 131 (gethash file old-hash t) | |
| 132 t))) | |
| 133 (if (and (not (file-newer-than-file-p file cusload-file)) | |
| 134 (not (eq old-cache t))) | |
| 135 (progn | |
| 136 (dolist (c old-cache) | |
| 137 (puthash (car c) (cdr c) hash)) | |
| 138 (puthash file old-cache hash-cache)) | |
| 139 (erase-buffer) | |
| 140 (insert-file-contents file) | |
| 141 (goto-char (point-min)) | |
| 142 (let ((name (file-name-sans-extension | |
| 143 (file-name-nondirectory file))) | |
| 144 cache | |
| 145 (first t)) | |
| 146 ;; Search for defcustom/defface/defgroup | |
| 147 ;; expressions, and evaluate them. | |
| 148 (while (re-search-forward | |
| 149 "^(defcustom\\|^(defface\\|^(defgroup" | |
| 150 nil t) | |
| 151 (when first | |
| 152 (message "Computing custom-loads for %s..." name) | |
| 153 (setq first nil)) | |
| 154 (beginning-of-line) | |
| 155 (let ((expr (read (current-buffer)))) | |
| 156 ;; We need to ignore errors here, so that | |
| 157 ;; defcustoms with :set don't bug out. Of | |
| 158 ;; course, their values will not be assigned in | |
| 159 ;; case of errors, but their `custom-group' | |
| 160 ;; properties will by that time be in place, and | |
| 161 ;; that's all we care about. | |
| 162 (ignore-errors | |
| 163 (eval expr)) | |
| 164 ;; Hash the file of the affected symbol. | |
| 165 (setf (gethash (nth 1 expr) hash) name) | |
| 166 ;; Remember the values computed. | |
| 167 (push (cons (nth 1 expr) name) cache))) | |
| 168 (or cache | |
| 169 (message "No custom-loads for %s" name)) | |
| 170 (puthash file cache hash-cache))) | |
| 171 )) | |
| 428 | 172 (cond |
| 173 ((zerop (hash-table-count hash)) | |
| 2544 | 174 (message "(No customization dependencies)") |
| 175 (write-region "" nil cusload-file)) | |
| 428 | 176 (t |
| 1298 | 177 (message "Generating %s...\n" cusload-base-file) |
| 428 | 178 (with-temp-file cusload-file |
| 179 (insert ";;; " cusload-base-file | |
| 180 " --- automatically extracted custom dependencies\n" | |
| 1298 | 181 "\n;;; Code:\n\n") |
| 182 (insert cusload-hash-table-marker) | |
| 183 (let ((print-readably t) | |
| 184 (standard-output (current-buffer))) | |
| 185 (princ hash-cache) | |
| 186 (terpri)) | |
| 187 (insert "(autoload 'custom-add-loads \"cus-load\")\n\n") | |
| 428 | 188 (mapatoms |
| 189 (lambda (sym) | |
| 190 (let ((members (get sym 'custom-group)) | |
| 191 item where found) | |
| 192 (when members | |
| 193 (while members | |
| 194 (setq item (car (car members)) | |
| 195 members (cdr members) | |
| 196 where (gethash item hash)) | |
| 197 (unless (or (null where) | |
| 198 (member where found)) | |
| 199 (if found | |
| 200 (insert " ") | |
| 201 (insert "(custom-add-loads '" | |
| 202 (prin1-to-string sym) " '(")) | |
| 203 (prin1 where (current-buffer)) | |
| 204 (push where found))) | |
| 205 (when found | |
| 206 (insert "))\n")))))) | |
| 207 (insert "\n;;; custom-load.el ends here\n")) | |
| 208 (clrhash hash))))))))) | |
| 209 | |
| 442 | 210 (defun Custom-make-one-dependency () |
| 211 "Extract custom dependencies from .el files in one dir, on the command line. | |
| 212 Like `Custom-make-dependencies' but snarfs only one command-line argument, | |
| 213 making it useful in a chain of batch commands in a single XEmacs invocation." | |
| 214 (let ((subdir (car command-line-args-left))) | |
| 215 (setq command-line-args-left (cdr command-line-args-left)) | |
| 216 (Custom-make-dependencies-1 (list subdir)))) | |
| 217 | |
| 218 ;;;###autoload | |
| 219 (defun Custom-make-dependencies (&optional subdirs) | |
| 220 "Extract custom dependencies from .el files in SUBDIRS. | |
| 221 SUBDIRS is a list of directories. If it is nil, the command-line | |
| 222 arguments are used. If it is a string, only that directory is | |
| 223 processed. This function is especially useful in batch mode. | |
| 224 | |
| 225 Batch usage: xemacs -batch -l cus-dep.el -f Custom-make-dependencies DIRS" | |
| 226 (interactive "DDirectory: ") | |
| 227 (and (stringp subdirs) | |
| 228 (setq subdirs (list subdirs))) | |
| 229 (or subdirs | |
| 230 ;; Usurp the command-line-args | |
| 231 (setq subdirs command-line-args-left | |
| 232 command-line-args-left nil)) | |
| 233 (Custom-make-dependencies-1 subdirs)) | |
| 234 | |
| 428 | 235 (provide 'cus-dep) |
| 236 | |
| 237 ;;; cus-dep.el ends here |
