]> code.delx.au - gnu-emacs/blobdiff - lisp/filesets.el
(Converting Representations): Update the description of what
[gnu-emacs] / lisp / filesets.el
index 0195d70d64c052375d5c67dfa78feaebaaf32ead..ae82aedb68b6780b80d99d8053572f4832c76eb0 100644 (file)
@@ -21,7 +21,7 @@
 ;; program's author or from the Free Software Foundation, Inc., 675 Mass
 ;; Ave, Cambridge, MA 02139, USA.
 
-(defvar filesets-version "1.8.1")
+(defvar filesets-version "1.8.4")
 (defvar filesets-homepage
   "http://members.a1.net/t.link/CompEmacsFilesets.html")
 
@@ -151,6 +151,38 @@ COND-FN takes one argument: the current element."
       (when (funcall cond-fn elt)
        (setq rv (append rv (list elt)))))))
 
+(defun filesets-ormap (fsom-pred lst)
+  "Return the tail of FSOM-LST for the head of which FSOM-PRED is non-nil."
+  (let ((fsom-lst lst)
+       (fsom-rv nil))
+    (while (and (not (null fsom-lst))
+               (null fsom-rv))
+      (if (funcall fsom-pred (car fsom-lst))
+         (setq fsom-rv fsom-lst)
+       (setq fsom-lst (cdr fsom-lst))))
+    fsom-rv))
+
+(defun filesets-some (fss-pred fss-lst)
+  "Return non-nil if FSS-PRED is non-nil for any element of FSS-LST. 
+Like `some', return the first value of FSS-PRED that is non-nil."
+  (catch 'exit
+    (dolist (fss-this fss-lst nil)
+      (let ((fss-rv (funcall fss-pred fss-this)))
+       (when fss-rv
+         (throw 'exit fss-rv))))))
+;(fset 'filesets-some 'some) ;; or use the cl function
+
+(defun filesets-member (fsm-item fsm-lst &rest fsm-keys)
+  "Find the first occurrence of FSM-ITEM in FSM-LST.
+It is supposed to work like cl's `member*'. At the moment only the :test
+key is supported."
+  (let ((fsm-test (or (plist-get fsm-keys ':test)
+                     (function equal))))
+    (filesets-ormap (lambda (fsm-this)
+                     (funcall fsm-test fsm-item fsm-this)) 
+                   fsm-lst)))
+;(fset 'filesets-member 'member*) ;; or use the cl function
+
 (defun filesets-sublist (lst beg &optional end)
   "Get the sublist of LST from BEG to END - 1."
   (let ((rv  nil)
@@ -262,26 +294,31 @@ COND-FN takes one argument: the current element."
   :type 'sexp
   :group 'filesets)
 
-(defcustom filesets-menu-path nil
-  "*The menu under which the filesets menu should be inserted.
+(if filesets-running-xemacs
+    (progn
+      (defcustom filesets-menu-path nil
+       "*The menu under which the filesets menu should be inserted.
 XEmacs specific; see `add-submenu' for documentation."
-  :set (function filesets-set-default)
-  :type 'sexp
-  :group 'filesets)
+       :set (function filesets-set-default)
+       :type 'sexp
+       :group 'filesets)
 
-(defcustom filesets-menu-before "File"
-  "*The name of a menu before which this menu should be added.
+      (defcustom filesets-menu-before "File"
+       "*The name of a menu before which this menu should be added.
 XEmacs specific; see `add-submenu' for documentation."
-  :set (function filesets-set-default)
-  :type 'sexp
-  :group 'filesets)
+       :set (function filesets-set-default)
+       :type 'sexp
+       :group 'filesets)
 
-(defcustom filesets-menu-in-menu nil
-  "*Use that instead of `current-menubar' as the menu to change.
+      (defcustom filesets-menu-in-menu nil
+       "*Use that instead of `current-menubar' as the menu to change.
 XEmacs specific; see `add-submenu' for documentation."
-  :set (function filesets-set-default)
-  :type 'sexp
-  :group 'filesets)
+       :set (function filesets-set-default)
+       :type 'sexp
+       :group 'filesets))
+  (defvar filesets-menu-path nil)
+  (defvar filesets-menu-before nil)
+  (defvar filesets-menu-in-menu nil))
 
 (defcustom filesets-menu-shortcuts-flag t
   "*Non-nil means to prepend menus with hopefully unique shortcuts."
@@ -305,12 +342,13 @@ XEmacs specific; see `add-submenu' for documentation."
   (if filesets-running-xemacs
       "~/.xemacs/filesets-cache.el"
       "~/.filesets-cache.el")
-  "*File to be used for saving the filesets menu between (X)Emacs
-sessions.  Set this to \"\", to disable caching of menus.
+  "*File to be used for saving the filesets menu between sessions.
+Set this to \"\", to disable caching of menus.
 Don't forget to check out `filesets-menu-ensure-use-cached'."
   :set (function filesets-set-default)
   :type 'file
   :group 'filesets)
+(put 'filesets-menu-cache-file 'risky-local-variable t)
 
 (defcustom filesets-menu-cache-contents
   '(filesets-be-docile-flag
@@ -378,8 +416,9 @@ Don't forget to check out `filesets-menu-ensure-use-cached'."
   :group 'filesets)
 
 (defcustom filesets-cache-hostname-flag nil
-  "*Non-nil means cache the hostname. If the current name differs from
-the cached one, rebuild the menu and create a new cache file."
+  "*Non-nil means cache the hostname.
+If the current name differs from the cached one,
+rebuild the menu and create a new cache file."
   :set (function filesets-set-default)
   :type 'boolean
   :group 'filesets)
@@ -407,7 +446,7 @@ will not be rewrapped if their length exceeds this value."
   :type 'integer
   :group 'filesets)
 
-(defcustom filesets-browse-dir-fn 'dired
+(defcustom filesets-browse-dir-function 'dired
   "*A function or command used for browsing directories.
 When using an external command, \"%s\" will be replaced with the
 directory's name.
@@ -425,7 +464,7 @@ Note: You have to manually rebuild the menu if you change this value."
                           :value nil))
   :group 'filesets)
 
-(defcustom filesets-open-file-fn 'filesets-find-or-display-file
+(defcustom filesets-open-file-function 'filesets-find-or-display-file
   "*The function used for opening files.
 
 `filesets-find-or-display-file' ... Filesets' default function for
@@ -448,7 +487,7 @@ Caveat: Changes will take effect only after rebuilding the menu."
                           :value nil))
   :group 'filesets)
 
-(defcustom filesets-save-buffer-fn 'save-buffer
+(defcustom filesets-save-buffer-function 'save-buffer
   "*The function used to save a buffer.
 Caveat: Changes will take effect after rebuilding the menu."
   :set (function filesets-set-default)
@@ -495,7 +534,7 @@ computer environments."
 (defcustom filesets-tree-max-level 3
   "*Maximum scan depth for directory trees.
 A :tree fileset is defined by a base directory the contents of which
-will be recursively added to the menu.  filesets-tree-max-level tells up
+will be recursively added to the menu.  `filesets-tree-max-level' tells up
 to which level the directory structure should be scanned/listed,
 i.e. how deep the menu should be.  Try something like
 
@@ -551,6 +590,7 @@ the filename."
                                       (function :tag "Function"
                                                 :value nil)))))
   :group 'filesets)
+(put 'filesets-commands 'risky-local-variable t)
 
 (defcustom filesets-external-viewers
   (let
@@ -607,7 +647,7 @@ i.e. on open-all-files-events or when running commands
 
 :constraintp FUNCTION ... use this viewer only if FUNCTION returns non-nil
 
-:constraint-flag SYMBOL ... use this viewer only if SYMBOL is non-nil
+:constraint-flag SEXP ... use this viewer only if SEXP evaluates to non-nil
 
 :open-hook HOOK ... run hooks after spawning the viewer -- mainly useful
 in conjunction with :capture-output
@@ -655,7 +695,7 @@ In order to view pdf or rtf files in an Emacs buffer, you could use these:
                                      :value (:constraint-flag)
                                      (const :format ""
                                             :value :constraint-flag)
-                                     (symbol :tag "Symbol"))
+                                     (sexp :tag "Symbol"))
                                (list :tag ":ignore-on-open-all"
                                      :value (:ignore-on-open-all t)
                                      (const  :format ""
@@ -694,7 +734,7 @@ In order to view pdf or rtf files in an Emacs buffer, you could use these:
                                              :value :capture-output)
                                      (boolean :tag "Boolean"))))))
   :group 'filesets)
-
+(put 'filesets-external-viewers 'risky-local-variable t)
 
 (defcustom filesets-ingroup-patterns
   '(("^.+\\.tex$" t
@@ -882,6 +922,7 @@ With duplicates removed, it would be:
                                  (const :format "" :value :preprocess)
                                  (function :tag "Function")))))))
   :group 'filesets)
+(put 'filesets-ingroup-patterns 'risky-local-variable t)
 
 (defcustom filesets-data
   nil
@@ -945,7 +986,7 @@ optional.
 
 In conjunction with the :tree tag, :save is void.  :open refers to the
 function used for opening files in a directory, not for opening the
-directory.  For browsing directories, `filesets-browse-dir-fn' is used.
+directory.  For browsing directories, `filesets-browse-dir-function' is used.
 
 Before using :ingroup, make sure that the file type is already
 defined in `filesets-ingroup-patterns'."
@@ -1007,6 +1048,7 @@ defined in `filesets-ingroup-patterns'."
                               :value (:open)
                               (const :format "" :value :open)
                               (function :tag "Function")))))))
+(put 'filesets-data 'risky-local-variable t)
 
 
 (defcustom filesets-query-user-limit 15
@@ -1065,7 +1107,7 @@ If SIMPLY-DO-IT is non-nil, the list is sorted regardless of
                   (lambda (a b)
                     (string< (upcase (funcall fni a))
                              (upcase (funcall fni b)))))))
-       (sort (copy-list lst) fn))
+       (sort (copy-sequence lst) fn))
     lst))
 
 (defun filesets-directory-files (dir &optional
@@ -1165,17 +1207,18 @@ non-nil."
                   filename)))
     (if (file-exists-p f)
        f
-      (some (lambda (dir)
-             (let ((dir (file-name-as-directory dir))
-                   (files (if (file-exists-p dir)
-                              (filesets-directory-files dir nil ':files)
-                            nil)))
-               (some (lambda (file)
-                       (if (equal filename (file-name-nondirectory file))
-                           (concat dir file)
-                         nil))
-                     files)))
-           path-list))))
+      (filesets-some
+       (lambda (dir)
+        (let ((dir (file-name-as-directory dir))
+              (files (if (file-exists-p dir)
+                         (filesets-directory-files dir nil ':files)
+                       nil)))
+          (filesets-some (lambda (file)
+                           (if (equal filename (file-name-nondirectory file))
+                               (concat dir file)
+                             nil))
+                         files)))
+       path-list))))
 
 
 (defun filesets-eviewer-get-props (entry)
@@ -1197,7 +1240,7 @@ non-nil."
 (defun filesets-get-external-viewer (file)
   "Find an external viewer for FILE."
   (let ((filename (file-name-nondirectory file)))
-    (some
+    (filesets-some
      (lambda (entry)
        (when (and (string-match (nth 0 entry) filename)
                  (filesets-eviewer-constraint-p entry))
@@ -1207,7 +1250,7 @@ non-nil."
 (defun filesets-get-external-viewer-by-name (name)
   "Get the external viewer definition called NAME."
   (when name
-    (some
+    (filesets-some
      (lambda (entry)
        (when (and (string-equal (nth 1 entry) name)
                  (filesets-eviewer-constraint-p entry))
@@ -1345,19 +1388,19 @@ not be opened."
       (filesets-find-or-display-file nil (cadr (assoc viewer lst))))))
 
 (defun filesets-browser-name ()
-  "Get the directory browser's name as defined in `filesets-browse-dir-fn'."
+  "Get the directory browser's name as defined in `filesets-browse-dir-function'."
   (cond
-   ((listp filesets-browse-dir-fn)
-    (car filesets-browse-dir-fn))
+   ((listp filesets-browse-dir-function)
+    (car filesets-browse-dir-function))
    (t
-    filesets-browse-dir-fn)))
+    filesets-browse-dir-function)))
 
 (defun filesets-browse-dir (dir)
-  "Browse DIR using `filesets-browse-dir-fn'."
-  (if (functionp filesets-browse-dir-fn)
-      (funcall filesets-browse-dir-fn dir)
-    (let ((name (car filesets-browse-dir-fn))
-         (args (format (cadr filesets-browse-dir-fn) (expand-file-name dir))))
+  "Browse DIR using `filesets-browse-dir-function'."
+  (if (functionp filesets-browse-dir-function)
+      (funcall filesets-browse-dir-function dir)
+    (let ((name (car filesets-browse-dir-function))
+         (args (format (cadr filesets-browse-dir-function) (expand-file-name dir))))
       (with-temp-buffer
        (start-process (concat "Filesets:" name)
                       "*Filesets external directory browser*"
@@ -1408,24 +1451,25 @@ Return DEFAULT if not found.  Return (car VALUE) if CARP is non-nil."
   "Return fileset ENTRY's mode: :files, :file, :tree, :pattern, or :ingroup.
 See `filesets-data'."
   (let ((data (filesets-data-get-data entry)))
-    (some (lambda (x)
-           (if (assoc x data)
-               x))
-         '(:files :tree :pattern :ingroup :file))))
+    (filesets-some
+     (lambda (x)
+       (if (assoc x data)
+          x))
+     '(:files :tree :pattern :ingroup :file))))
 
 (defun filesets-entry-get-open-fn (fileset-name &optional fileset-entry)
   "Get the open-function for FILESET-NAME.
 Use FILESET-ENTRY for finding the open function, if provided."
   (filesets-data-get (or fileset-entry
                         (filesets-get-fileset-from-name fileset-name))
-                    ':open filesets-open-file-fn t))
+                    ':open filesets-open-file-function t))
 
 (defun filesets-entry-get-save-fn (fileset-name &optional fileset-entry)
   "Get the save-function for FILESET-NAME.
 Use FILESET-ENTRY for finding the save function, if provided."
   (filesets-data-get (or fileset-entry
                         (filesets-get-fileset-from-name fileset-name))
-                    ':save filesets-save-buffer-fn t))
+                    ':save filesets-save-buffer-function t))
 
 (defun filesets-entry-get-files (entry)
   "Get the file list for fileset ENTRY."
@@ -1751,7 +1795,8 @@ User will be queried, if no fileset name is provided."
     (if entry
        (let* ((files  (filesets-entry-get-files entry))
               (this   (buffer-file-name buffer))
-              (inlist (member* this files :test 'filesets-files-equalp)))
+              (inlist (filesets-member this files
+                                       :test 'filesets-files-equalp)))
          (cond
           (inlist
            (message "Filesets: '%s' is already in '%s'" this name))
@@ -1776,7 +1821,8 @@ User will be queried, if no fileset name is provided."
     (if entry
        (let* ((files  (filesets-entry-get-files entry))
               (this   (buffer-file-name buffer))
-              (inlist (member* this files :test 'filesets-files-equalp)))
+              (inlist (filesets-member this files
+                                       :test 'filesets-files-equalp)))
          ;;(message "%s %s %s" files this inlist)
          (if (and files this inlist)
              (let ((new (list (cons ':files (delete (car inlist) files)))))
@@ -1940,11 +1986,11 @@ LOOKUP-NAME is used as lookup name for retrieving fileset specific settings."
                      (and (stringp a)
                           (stringp b)
                           (string-match a b))))))
-    (some (lambda (x)
-           (if (funcall fn (car x) masterfile)
-               (nth pos x)
-             nil))
-         filesets-ingroup-patterns)))
+    (filesets-some (lambda (x)
+                    (if (funcall fn (car x) masterfile)
+                        (nth pos x)
+                      nil))
+                  filesets-ingroup-patterns)))
 
 (defun filesets-ingroup-get-pattern (master)
   "Access to `filesets-ingroup-patterns'.  Extract patterns."
@@ -2020,7 +2066,7 @@ LOOKUP-NAME is used as lookup name for retrieving fileset specific settings."
                      (when (and f
                                 (not (member f flist))
                                 (or (not remdupl-flag)
-                                    (not (member*
+                                    (not (filesets-member
                                           f filesets-ingroup-files
                                           :test 'filesets-files-equalp))))
                        (let ((no-stub-flag
@@ -2464,7 +2510,6 @@ Set up hooks, load the cache file -- if existing -- and build the menu."
 (provide 'filesets)
 
 ;;; Local Variables:
-;;; time-stamp-format:"%:y-%02m-%02d"
 ;;; sentence-end-double-space:t
 ;;; End: