From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Lars Hansen Newsgroups: gmane.emacs.devel Subject: Re: desktop.el and minor modes Date: Mon, 31 May 2004 23:22:37 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <40BBA21D.7060003@math.ku.dk> References: <87aczpn09z.fsf@mail.jurta.org> <40BB0701.9020807@math.ku.dk> <40BB3018.4090209@math.ku.dk> <87zn7opuu2.fsf@mail.jurta.org> <40BB5F7E.9040900@math.ku.dk> <20040531192600.GD2501@fencepost> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1086038930 10861 80.91.224.253 (31 May 2004 21:28:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 31 May 2004 21:28:50 +0000 (UTC) Cc: Juri Linkov , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon May 31 23:28:40 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BUuKm-0002gR-00 for ; Mon, 31 May 2004 23:28:40 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BUuKl-00048H-00 for ; Mon, 31 May 2004 23:28:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUuKx-0007id-UC for emacs-devel@quimby.gnus.org; Mon, 31 May 2004 17:28:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BUuKJ-0006fL-5c for emacs-devel@gnu.org; Mon, 31 May 2004 17:28:11 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BUuKF-0006by-PZ for emacs-devel@gnu.org; Mon, 31 May 2004 17:28:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUuKF-0006b9-H8 for emacs-devel@gnu.org; Mon, 31 May 2004 17:28:07 -0400 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1BUuJM-0002Rw-1J; Mon, 31 May 2004 17:27:12 -0400 Original-Received: from [213.170.224.162] (helo=smtp.kabelnettet.dk) by mx20.gnu.org with esmtp (Exim 4.34) id 1BUuEy-0000v5-77; Mon, 31 May 2004 17:22:40 -0400 Original-Received: from math.ku.dk (0x52b410db.dhcp.kabelnettet.dk [82.180.16.219]) by smtp.kabelnettet.dk (Postfix) with ESMTP id 1D00F60990E; Mon, 31 May 2004 23:22:36 +0200 (CEST) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021213 Debian/1.2.1-2.bunk X-Accept-Language: en Original-To: Miles Bader In-Reply-To: <20040531192600.GD2501@fencepost> X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24313 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24313 Miles Bader wrote: >You really ought to use `define-minor-mode' rather than rolling your own >minor-mode function. > Right. What about this: diff -u -r1.54 dired-x.el --- lisp/dired-x.el 31 Mar 2004 16:09:18 -0000 1.54 +++ lisp/dired-x.el 31 May 2004 21:18:15 -0000 @@ -50,7 +50,7 @@ ;; (add-hook 'dired-mode-hook ;; (function (lambda () ;; ;; Set buffer-local variables here. For example: -;; ;; (setq dired-omit-files-p t) +;; ;; (dired-omit-mode 1) ;; ))) ;; ;; At load time dired-x.el will install itself, redefine some functions, and @@ -74,7 +74,7 @@ ;; dired-guess-shell-znew-switches ;; dired-guess-shell-alist-user ;; dired-clean-up-buffers-too -;; dired-omit-files-p +;; dired-omit-mode ;; dired-omit-files ;; dired-omit-extensions ;; dired-omit-size-limit @@ -154,19 +154,27 @@ (other :tag "non-writable only" if-file-read-only)) :group 'dired-x) -(defcustom dired-omit-files-p nil - "*If non-nil, \"uninteresting\" files are not listed (buffer-local). -Use \\[dired-omit-toggle] to toggle its value. +(define-minor-mode dired-omit-mode + "Toggle Dired-Omit mode. +With numeric ARG, enable Dired-Omit mode if ARG is positive, disable +otherwise. Enabling and disabling is buffer-local. +If enabled, \"uninteresting\" files are not listed. Uninteresting files are those whose filenames match regexp `dired-omit-files', plus those ending with extensions in `dired-omit-extensions'." - :type 'boolean - :group 'dired-x) -(make-variable-buffer-local 'dired-omit-files-p) + :group 'dired-x + (if dired-omit-mode + ;; This will mention how many lines were omitted: + (let ((dired-omit-size-limit nil)) (dired-omit-expunge)) + (revert-buffer))) + +;; For backward compatibility +(defvaralias 'dired-omit-files-p 'dired-omit-mode) +(make-obsolete-variable 'dired-omit-files-p 'dired-omit-mode) (defcustom dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$" "*Filenames matching this regexp will not be displayed. -This only has effect when `dired-omit-files-p' is t. See interactive function -`dired-omit-toggle' \(\\[dired-omit-toggle]\) and variable +This only has effect when `dired-omit-mode' is t. See interactive function +`dired-omit-mode' \(\\[dired-omit-mode]\) and variable `dired-omit-extensions'. The default is to omit `.', `..', auto-save files and lock files." :type 'regexp @@ -230,7 +238,7 @@ ;;; KEY BINDINGS. -(define-key dired-mode-map "\M-o" 'dired-omit-toggle) +(define-key dired-mode-map "\M-o" 'dired-omit-mode) (define-key dired-mode-map "\M-(" 'dired-mark-sexp) (define-key dired-mode-map "*(" 'dired-mark-sexp) (define-key dired-mode-map "*." 'dired-mark-extension) @@ -268,7 +276,7 @@ \\[dired-info]\t-- run info on file \\[dired-man]\t-- run man on file \\[dired-do-find-marked-files]\t-- visit all marked files simultaneously - \\[dired-omit-toggle]\t-- toggle omitting of files + \\[dired-omit-mode]\t-- toggle omitting of files \\[dired-mark-sexp]\t-- mark by Lisp expression \\[dired-copy-filename-as-kill]\t-- copy the file or subdir names into the kill ring. \t You can feed it to other commands using \\[yank]. @@ -280,7 +288,7 @@ `dired-bind-info' `dired-bind-man' `dired-vm-read-only-folders' - `dired-omit-files-p' + `dired-omit-mode' `dired-omit-files' `dired-omit-extensions' `dired-omit-size-limit' @@ -450,9 +458,9 @@ (dired-insert-subdir (file-name-directory file)) (dired-goto-file file)) ;; Toggle omitting, if it is on, and try again. - (if dired-omit-files-p + (if dired-omit-mode (progn - (dired-omit-toggle) + (dired-omit-mode) (dired-goto-file file)))))))) (defun dired-jump-other-window () @@ -479,31 +487,18 @@ Should never be used as marker by the user or other packages.") (defun dired-omit-startup () - (or (assq 'dired-omit-files-p minor-mode-alist) + (or (assq 'dired-omit-mode minor-mode-alist) (setq minor-mode-alist - (append '((dired-omit-files-p + (append '((dired-omit-mode (:eval (if (eq major-mode 'dired-mode) " Omit" "")))) minor-mode-alist)))) -(defun dired-omit-toggle (&optional flag) - "Toggle omitting files matching `dired-omit-files' and `dired-omit-extensions'. -With an arg, and if omitting was off, don't toggle and just mark the - files but don't actually omit them. -With an arg, and if omitting was on, turn it off but don't refresh the buffer." - (interactive "P") - (if flag - (if dired-omit-files-p - (setq dired-omit-files-p (not dired-omit-files-p)) - (dired-mark-unmarked-files (dired-omit-regexp) nil nil - dired-omit-localp)) - ;; no FLAG - (setq dired-omit-files-p (not dired-omit-files-p)) - (if (not dired-omit-files-p) - (revert-buffer) - ;; this will mention how many were omitted: - (let ((dired-omit-size-limit nil)) - (dired-omit-expunge))))) +(defun dired-mark-omitted () + "Mark files matching `dired-omit-files' and `dired-omit-extensions'." + (interactive) + (let ((dired-omit-mode nil)) (revert-buffer)) ;; Show omitted files + (dired-mark-unmarked-files (dired-omit-regexp) nil nil dired-omit-localp)) (defvar dired-omit-extensions (append completion-ignored-extensions @@ -515,12 +510,12 @@ `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions', and `dired-texinfo-unclean-extensions'. -See interactive function `dired-omit-toggle' \(\\[dired-omit-toggle]\) and -variables `dired-omit-files-p' and `dired-omit-files'.") +See interactive function `dired-omit-mode' \(\\[dired-omit-mode]\) and +variables `dired-omit-mode' and `dired-omit-files'.") (defun dired-omit-expunge (&optional regexp) "Erases all unmarked files matching REGEXP. -Does nothing if global variable `dired-omit-files-p' is nil, or if called +Does nothing if global variable `dired-omit-mode' is nil, or if called non-interactively and buffer is bigger than `dired-omit-size-limit'. If REGEXP is nil or not specified, uses `dired-omit-files', and also omits filenames ending in `dired-omit-extensions'. @@ -529,14 +524,14 @@ This functions works by temporarily binding `dired-marker-char' to `dired-omit-marker-char' and calling `dired-do-kill-lines'." (interactive "sOmit files (regexp): ") - (if (and dired-omit-files-p + (if (and dired-omit-mode (or (interactive-p) (not dired-omit-size-limit) (< (buffer-size) dired-omit-size-limit) (progn (message "Not omitting: directory larger than %d characters." dired-omit-size-limit) - (setq dired-omit-files-p nil) + (setq dired-omit-mode nil) nil))) (let ((omit-re (or regexp (dired-omit-regexp))) (old-modified-p (buffer-modified-p)) @@ -589,7 +584,7 @@ (defun dired-omit-new-add-entry (filename &optional marker-char relative) ;; This redefines dired-aux.el's dired-add-entry to avoid calling ls for ;; files that are going to be omitted anyway. - (if dired-omit-files-p + (if dired-omit-mode ;; perhaps return t without calling ls (let ((omit-re (dired-omit-regexp))) (if (or (string= omit-re "") @@ -842,7 +837,7 @@ (save-excursion (set-buffer (get-buffer-create " *dot-dired*")) (erase-buffer) - (insert "Local Variables:\ndired-omit-files-p: t\nEnd:\n") + (insert "Local Variables:\ndired-omit-mode: t\nEnd:\n") (write-file dired-local-variables-file) (kill-buffer (current-buffer))) @@ -1692,7 +1687,7 @@ 'dired-guess-shell-znew-switches 'dired-guess-shell-alist-user 'dired-clean-up-buffers-too - 'dired-omit-files-p + 'dired-omit-mode 'dired-omit-files 'dired-omit-extensions )