;;; filesets.el --- handle group of files
-;; Copyright (C) 2002 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
;; Author: Thomas Link <t.link@gmx.at>
+;; Maintainer: FSF
;; Keywords: filesets convenience
;; This file is part of GNU Emacs.
;; GNU General Public License for more details.
;; A copy of the GNU General Public License can be obtained from this
-;; program's author or from the Free Software Foundation, Inc., 675 Mass
-;; Ave, Cambridge, MA 02139, USA.
+;; program's author or from the Free Software Foundation, Inc.,
+;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
(defvar filesets-version "1.8.4")
(defvar filesets-homepage
;; pattern, a base directory and a search pattern (for files), or an
;; inclusion group (i.e. a base file including other files).
-;; Usage: 1. Put (require 'filesets) into your start-up file. 2. Type
-;; M-x filesets-edit or choose "Edit Filesets" from the menu. 3. Save
-;; your customizations.
+;; Usage:
+;; 1. Put (require 'filesets) and (filesets-init) in your .emacs file.
+;; 2. Type ;; M-x filesets-edit or choose "Edit Filesets" from the menu.
+;; 3. Save your customizations.
;; Caveat: Fileset names have to be unique.
;;- better handling of different customization scenarios
+;; Data gathering should be better separated from building the menu
+;; so that one could (1) use filesets without installing the menu
+;; and (2) create new "frontends" to speedbar and others.
+
+;; The functionality to call external viewers should be isolated in
+;; an extra package and possibly integrated with the MIME
+;; handling.
;;; Credits:
Is buffer local variable.")
(defvar filesets-verbosity 1
- "An integer defining the level of verbosity. 0 means no messages
-at all.")
+ "An integer defining the level of verbosity.
+0 means no messages at all.")
(defvar filesets-menu-ensure-use-cached
(and filesets-running-xemacs
- (not (emacs-version>= 21 5)))
+ (if (fboundp 'emacs-version>=)
+ (not (emacs-version>= 21 5))))
"Make sure (X)Emacs uses filesets' cache.
Well, if you use XEmacs (prior to 21.5?) custom.el is loaded after
(setq rv (append rv (list elt)))))))
(defun filesets-ormap (fsom-pred lst)
- "Return the the tail of FSOM-LST for the head of which FSOM-PRED is non-nil."
+ "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))
fsom-rv))
(defun filesets-some (fss-pred fss-lst)
- "Return non-nil if FSS-PRED is non-nil for any element of 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 ((fsm-test (or (plist-get fsm-keys ':test)
(function equal))))
(filesets-ormap (lambda (fsm-this)
- (funcall fsm-test fsm-item fsm-this))
+ (funcall fsm-test fsm-item fsm-this))
fsm-lst)))
;(fset 'filesets-member 'member*) ;; or use the cl function
(let ((this (shell-command-to-string
(format "which --skip-alias %s 2> /dev/null | head -n 1"
cmd-list))))
- (if (equal this "")
+ (if (equal this "")
nil
(file-name-nondirectory (substring this 0 (- (length this) 1))))))
; (customize-set-variable var val))
; (filesets-build-menu))
+;; It seems this is a workaround for the XEmacs issue described in the
+;; doc-string of filesets-menu-ensure-use-cached. Under Emacs this is
+;; essentially just `set-default'.
(defun filesets-set-default (sym val &optional init-flag)
- "Set-default wrapper function used in conjunction with `defcustom'."
+ "Set-default wrapper function used in conjunction with `defcustom'.
+If SYM is in the list `filesets-ignore-next-set-default', delete
+it from that list, and return nil. Otherwise, set the value of
+SYM to VAL and return t. If INIT-FLAG is non-nil, set with
+`custom-initialize-set', otherwise with `set-default'."
(let ((ignore-flag (member sym filesets-ignore-next-set-default)))
(if ignore-flag
(setq filesets-ignore-next-set-default
(setq filesets-has-changed-flag t)))
; (filesets-reset-fileset nil t)))
+(defvar filesets-data)
+
(defun filesets-data-set-default (sym val)
"Set the default for `filesets-data'."
(if filesets-menu-use-cached-flag
(dolist (x modified-filesets)
(filesets-reset-fileset (car x))))))
(filesets-set-default sym val))
-
-
-
+\f
;;; configuration
(defgroup filesets nil
"The fileset swapper."
:prefix "filesets-"
- :group 'convenience)
+ :group 'convenience
+ :version "22.1")
(defcustom filesets-menu-name "Filesets"
"*Filesets' menu name."
:type 'sexp
:group 'filesets)
-(if
- (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)
-
- (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)
-
- (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))
- (defvar filesets-menu-path nil)
- (defvar filesets-menu-before nil)
- (defvar filesets-menu-in-menu nil))
+(defcustom filesets-menu-path nil
+ "*The menu under which the filesets menu should be inserted.
+See `add-submenu' for documentation."
+ :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.
+See `add-submenu' for documentation."
+ :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.
+See `add-submenu' for documentation."
+ :set (function filesets-set-default)
+ :type 'sexp
+ :group 'filesets)
(defcustom filesets-menu-shortcuts-flag t
"*Non-nil means to prepend menus with hopefully unique shortcuts."
(defcustom filesets-menu-cache-file
(if filesets-running-xemacs
"~/.xemacs/filesets-cache.el"
- "~/.filesets-cache.el")
+ "~/.emacs.d/filesets-cache.el")
"*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'."
(defcustom filesets-menu-cache-contents
'(filesets-be-docile-flag
filesets-submenus
- filesets-menu-cache
+ filesets-menu-cache
filesets-ingroup-cache)
"*Stuff we want to save in `filesets-menu-cache-file'.
Has the form ((FILE-PATTERN VIEWER PROPERTIES) ...), VIEWER being either a
function or a command name as string.
-Properties is an association list determining filesets' behaviour in
-several conditions. Choose one from this list:
+Properties is an association list determining filesets' behavior in
+several conditions. Choose one from this list:
:ignore-on-open-all ... Don't open files of this type automatically --
i.e. on open-all-files-events or when running commands
(:get-file-name (lambda (master file)
(filesets-which-file master
(concat file ".sty")
- (filesets-convert-path-list
+ (filesets-convert-path-list
(or (getenv "MY_TEXINPUTS")
(getenv "TEXINPUTS")))))))
((:name "Include")
(:get-file-name (lambda (master file)
(filesets-which-file master
(concat file ".tex")
- (filesets-convert-path-list
+ (filesets-convert-path-list
(or (getenv "MY_TEXINPUTS")
(getenv "TEXINPUTS"))))))
(:scan-depth 5))
(:get-file-name (lambda (master file)
(filesets-which-file master
(concat file ".tex")
- (filesets-convert-path-list
+ (filesets-convert-path-list
(or (getenv "MY_TEXINPUTS")
(getenv "TEXINPUTS"))))))
(:scan-depth 5))
(:get-file-name (lambda (master file)
(filesets-which-file master
(concat file ".bib")
- (filesets-convert-path-list
+ (filesets-convert-path-list
(or (getenv "MY_BIBINPUTS")
(getenv "BIBINPUTS")))))))))
("^.+\\.el$" t
:set (function filesets-set-default)
:type 'integer
:group 'filesets)
-
-
+\f
;;; Emacs compatibility
(eval-and-compile
(if filesets-running-xemacs
- (progn
- (fset 'filesets-error 'error)
- (fset 'filesets-add-submenu 'add-submenu))
+ (fset 'filesets-error 'error)
(require 'easymenu)
-
+
(defun filesets-error (class &rest args)
"`error' wrapper."
(error (mapconcat 'identity args " ")))
- ;; This should work for 21.1 Emacs
- (defun filesets-add-submenu (menu-path submenu &optional
- before in-menu)
- "`easy-menu-define' wrapper."
- (easy-menu-define
- filesets-submenu global-map "Filesets menu" submenu))
))
(defun filesets-filter-dir-names (lst &optional negative)
(let ((files nil)
(dirs nil))
(dolist (this (file-name-all-completions "" dir))
- (cond
+ (cond
((string-match "^\\.+/$" this)
nil)
((string-match "[:/\\]$" this)
(when (or (not match-dirs-flag)
(not pattern)
(string-match pattern this))
- (filesets-message 5 "Filesets: matched dir %S with pattern %S"
+ (filesets-message 5 "Filesets: matched dir %S with pattern %S"
this pattern)
(setq dirs (cons this dirs))))
(t
(when (or (not pattern)
(string-match pattern this))
- (filesets-message 5 "Filesets: matched file %S with pattern %S"
+ (filesets-message 5 "Filesets: matched file %S with pattern %S"
this pattern)
(setq files (cons (if full-flag
(concat (file-name-as-directory dir) this)
(filesets-get-external-viewer filename)))))
(when def
(filesets-alist-get def property nil t))))
-
+
(defun filesets-reset-filename-on-change ()
"Reset a buffer's filename if the buffer is being modified."
(when filesets-output-buffer-flag
(run-hooks 'oh))
(set-buffer-modified-p nil)
(setq buffer-read-only t)
- (beginning-of-buffer))
+ (goto-char (point-min)))
(when oh
(run-hooks 'oh))))
(filesets-error 'error
(filesets-data-get entry ':ingroup nil t))
(defun filesets-file-open (open-function file-name &optional fileset-name)
- "Open FILE-NAME using OPEN-FUNCTION. If OPEN-FUNCTION is nil, it's
-value will be deduced from FILESET-NAME"
+ "Open FILE-NAME using OPEN-FUNCTION. If OPEN-FUNCTION is nil, its
+value will be deduced from FILESET-NAME."
(let ((open-function (or open-function
(filesets-entry-get-open-fn fileset-name))))
(if (file-readable-p file-name)
(cond
((and (symbolp this) (fboundp this))
(let ((x (funcall this)))
- (setq rv (append rv (if (listp x) x (list x))))))
+ (setq rv (append rv (if (listp x) x (list x))))))
(t
(setq rv (append rv (list this))))))))
(defun filesets-cmd-show-result (cmd output)
"Show OUTPUT of CMD (a shell command)."
(pop-to-buffer "*Filesets: Shell Command Output*")
- (end-of-buffer)
+ (with-no-warnings
+ (end-of-buffer))
(insert "*** ")
(insert cmd)
(newline)
(or (equal mode ':ingroup)
(equal mode ':tree)))
(filesets-get-filelist fileset mode event)
- (filesets-get-filelist
+ (filesets-get-filelist
(filesets-get-fileset-from-name name)
mode event))))
(when files
(save-restriction
(let ((buffer (filesets-find-file this)))
(when buffer
- (beginning-of-buffer)
+ (goto-char (point-min))
(let ()
(cond
((stringp fn)
(if (equal txt "") "" " ")
(format "%s" this))))))))
(cmd (concat fn " " args)))
- (filesets-cmd-show-result
+ (filesets-cmd-show-result
cmd (shell-command-to-string cmd))))
((symbolp fn)
(let ((args
(name (or name
(completing-read
(format "Add '%s' to fileset: " buffer)
- filesets-data nil t)))
- (entry (assoc name filesets-data)))
+ filesets-data nil)))
+ (entry (or (assoc name filesets-data)
+ (when (y-or-n-p
+ (format "Fileset %s does not exist. Create it?"
+ name))
+ (progn
+ (add-to-list 'filesets-data (list name '(:files)))
+ (message
+ "Fileset %s created. Call `M-x filesets-save-config' to save."
+ name)
+ (car filesets-data))))))
(if entry
(let* ((files (filesets-entry-get-files entry))
(this (buffer-file-name buffer))
(cond
(inlist
(message "Filesets: '%s' is already in '%s'" this name))
- ((and (equal (filesets-entry-mode entry) ':files)
+ ((and (equal (filesets-entry-mode entry) ':files)
this)
(filesets-entry-set-files entry (cons this files) t)
(filesets-set-config name 'filesets-data filesets-data))
(if (null (cdr x))
""
", "))))
- (setq rv
+ (setq rv
(concat
rv
(if filesets-menu-shortcuts-flag
(append rv
(if files
`((,nm
- [,(concat "Inclusion Group: "
+ [,(concat "Inclusion Group: "
(file-name-nondirectory master))
(filesets-open ':ingroup ',master ',fsn)]
"---"
(mapcar
(lambda (this)
(setq count (+ count 1))
- (let ((ff (filesets-ingroup-collect-build-menu
+ (let ((ff (filesets-ingroup-collect-build-menu
fs (list this) count)))
(if (= (length ff) 1)
(car ff)
(let* ((x (file-name-as-directory x))
(xx (concat dir x))
(dd (filesets-build-dir-submenu-now
- (+ level 1) depth entry
+ (+ level 1) depth entry
lookup-name xx patt fd))
(nm (concat (filesets-get-shortcut count)
x)))
(append
dirsmenu
filesmenu))
- (filesets-get-menu-epilog `(,dir ,patt) ':tree
+ (filesets-get-menu-epilog `(,dir ,patt) ':tree
lookup-name rebuild-flag)))
nil))
(filesets-menu-cache-file-save-maybe)))
(let ((cb (current-buffer)))
(when (not (member cb filesets-updated-buffers))
- (filesets-add-submenu
+ (add-submenu
filesets-menu-path
`(,filesets-menu-name
("# Filesets"
filesets-menu-in-menu)
(setq filesets-updated-buffers
(cons cb filesets-updated-buffers))
- (message nil)
+ ;; This wipes out other messages in the echo area.
+ ;; (message nil)
;;(message "Filesets updated: %s" cb)
)))
(with-temp-buffer
(dolist (this filesets-menu-cache-contents)
(if (get this 'custom-type)
- (progn
+ (progn
(insert (format "(setq-default %s '%S)" this (eval this)))
(when filesets-menu-ensure-use-cached
(newline)
\(\"Test\" (:pattern \"~/dir/^pattern$\"))
--> \(\"Test\" (:pattern \"~/dir/\" \"^pattern$\"))
-2. `filesets-data': Change all occurances of \":document\" to \":ingroup\":
+2. `filesets-data': Change all occurrences of \":document\" to \":ingroup\":
\(\(\"Test\" \(:document \"~/dir/file\"))
--> \(\(\"Test\" \(:ingroup \"~/dir/file\"))
(defun filesets-exit ()
(filesets-menu-cache-file-save-maybe))
+;;;###autoload
(defun filesets-init ()
"Filesets initialization.
Set up hooks, load the cache file -- if existing -- and build the menu."
(filesets-build-menu)))
-;;; run
-(filesets-init)
-
(provide 'filesets)
;;; Local Variables:
-;;; time-stamp-format:"%:y-%02m-%02d"
;;; sentence-end-double-space:t
;;; End:
+;;; arch-tag: 2c03f85f-c3df-4cec-b0a3-b46fd5592d70
;;; filesets.el ends here