Mercurial > hg > xemacs-beta
comparison lisp/dired/dired-chmod.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;;; dired-chmod.el - interactive editing of file permissions in Dired listings. | |
2 | |
3 ;;; Copyright (C) 1995 Russell Ritchie, <Russell.Ritchie@gssec.bt.co.uk> | |
4 | |
5 ;; Keywords: dired extensions, faces, interactive chmod | |
6 | |
7 ;; This file is part of XEmacs. | |
8 | |
9 ;; XEmacs is free software; you can redistribute it and/or modify it | |
10 ;; under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; XEmacs is distributed in the hope that it will be useful, but | |
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 ;; General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with XEmacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 ;;; To turn this on do: | |
25 ;;; (require 'dired-chmod) | |
26 ;;; (add-hook 'dired-after-readin-hook 'dired-permissions-highlight) | |
27 | |
28 (require 'dired) ; | |
29 | |
30 (defvar dired-permissions-regexp "[-r][-w][-Ssx][-r][-w][-sx][-r][-w][-xst]" | |
31 "Regexp matching the file permissions part of a dired line.") | |
32 | |
33 (defvar dired-pre-permissions-regexp "^. [0-9 ]*[-d]" | |
34 "Regexp matching the preamble to file permissions part of a dired line. | |
35 This shouldn't match socket or symbolic link lines (which aren't editable).") | |
36 | |
37 (or (find-face 'dired-face-permissions) | |
38 (and | |
39 (make-face 'dired-face-permissions) | |
40 (set-face-foreground 'dired-face-permissions '(color . "mediumorchid") | |
41 nil nil 'append) | |
42 (set-face-underline-p 'dired-face-permissions '((mono . t) | |
43 (grayscale . t)) nil | |
44 nil 'append))) | |
45 | |
46 (defun dired-activate-extent (extent keys fn) | |
47 (let ((keymap (make-sparse-keymap))) | |
48 (while keys | |
49 (define-key keymap (car keys) fn) | |
50 (setq keys (cdr keys))) | |
51 (set-extent-face extent 'dired-face-permissions) | |
52 (set-extent-property extent 'keymap keymap) | |
53 (set-extent-property extent 'highlight t) | |
54 (set-extent-property | |
55 extent 'help-echo | |
56 "Type rsStwx to set file permissions to taste interactively."))) | |
57 | |
58 (defun dired-chmod-do-chmod (state) | |
59 (let* ((file (dired-get-filename)) | |
60 (operation (concat "chmod" " " state " " file)) | |
61 (failure (apply (function dired-check-process) | |
62 operation "chmod" state (list file))) | |
63 (here (point))) | |
64 (dired-do-redisplay) | |
65 (goto-char (+ here 1)) | |
66 (dired-make-permissions-interactive) | |
67 (if failure | |
68 (dired-log-summary | |
69 (message "%s: error - type W to see why." operation))))) | |
70 | |
71 (defun dired-u-r () | |
72 (interactive) | |
73 (if (equal (event-key last-command-event) ?r) | |
74 (dired-chmod-do-chmod "u+r") | |
75 (dired-chmod-do-chmod "u-r"))) | |
76 | |
77 (defun dired-u-w () | |
78 (interactive) | |
79 (if (equal (event-key last-command-event) ?w) | |
80 (dired-chmod-do-chmod "u+w") | |
81 (dired-chmod-do-chmod "u-w"))) | |
82 | |
83 (defun dired-u-x () | |
84 (interactive) | |
85 (let ((key (event-key last-command-event))) | |
86 (cond ((equal key ?s) (dired-chmod-do-chmod "u+s")) | |
87 ((equal key ?S) (dired-chmod-do-chmod "u+S")) | |
88 ((equal key ?x) (dired-chmod-do-chmod "u+x")) | |
89 (t (dired-chmod-do-chmod (cond ((looking-at "s") "u-s") | |
90 ((looking-at "S") "u-S") | |
91 ((looking-at "x") "u-x") | |
92 (t "u-x"))))))) | |
93 | |
94 (defun dired-g-r () | |
95 (interactive) | |
96 (if (equal (event-key last-command-event) ?r) | |
97 (dired-chmod-do-chmod "g+r") | |
98 (dired-chmod-do-chmod "g-r"))) | |
99 | |
100 (defun dired-g-w () | |
101 (interactive) | |
102 (if (equal (event-key last-command-event) ?w) | |
103 (dired-chmod-do-chmod "g+w") | |
104 (dired-chmod-do-chmod "g-w"))) | |
105 | |
106 (defun dired-g-x () | |
107 (interactive) | |
108 (let ((key (event-key last-command-event))) | |
109 (cond ((equal key ?s) (dired-chmod-do-chmod "g+s")) | |
110 ((equal key ?x) (dired-chmod-do-chmod "g+x")) | |
111 (t (dired-chmod-do-chmod (if (looking-at "s") "g-s" "g-x")))))) | |
112 | |
113 (defun dired-o-r () | |
114 (interactive) | |
115 (if (equal (event-key last-command-event) ?r) | |
116 (dired-chmod-do-chmod "o+r") | |
117 (dired-chmod-do-chmod "o-r"))) | |
118 | |
119 (defun dired-o-w () | |
120 (interactive) | |
121 (if (equal (event-key last-command-event) ?w) | |
122 (dired-chmod-do-chmod "o+w") | |
123 (dired-chmod-do-chmod "o-w"))) | |
124 | |
125 (defun dired-o-x () | |
126 (interactive) | |
127 (let ((key (event-key last-command-event))) | |
128 (cond ((equal key ?s) (dired-chmod-do-chmod "o+s")) | |
129 ((equal key ?t) (dired-chmod-do-chmod "o+t")) | |
130 ((equal key ?x) (dired-chmod-do-chmod "o+x")) | |
131 (t (dired-chmod-do-chmod (cond ((looking-at "s") "o-s") | |
132 ((looking-at "t") "o-t") | |
133 ((looking-at "x") "o-x") | |
134 (t "o-x"))))))) | |
135 | |
136 ;;;###autoload | |
137 (defun dired-make-permissions-interactive () | |
138 (save-excursion | |
139 (beginning-of-line 0) | |
140 (if (and (re-search-forward dired-pre-permissions-regexp (end-of-line) t) | |
141 (looking-at dired-permissions-regexp)) | |
142 (let* ((start (point)) | |
143 (u-r-extent (make-extent start (+ start 1))) | |
144 (u-w-extent (make-extent (+ start 1) (+ start 2))) | |
145 (u-x-extent (make-extent (+ start 2) (+ start 3))) | |
146 (g-r-extent (make-extent (+ start 3) (+ start 4))) | |
147 (g-w-extent (make-extent (+ start 4) (+ start 5))) | |
148 (g-x-extent (make-extent (+ start 5) (+ start 6))) | |
149 (o-r-extent (make-extent (+ start 6) (+ start 7))) | |
150 (o-w-extent (make-extent (+ start 7) (+ start 8))) | |
151 (o-x-extent (make-extent (+ start 8) (+ start 9)))) | |
152 (dired-activate-extent u-r-extent '(r space) 'dired-u-r) | |
153 (dired-activate-extent u-w-extent '(w space) 'dired-u-w) | |
154 (dired-activate-extent u-x-extent '(s S x space) 'dired-u-x) | |
155 (dired-activate-extent g-r-extent '(r space) 'dired-g-r) | |
156 (dired-activate-extent g-w-extent '(w space) 'dired-g-w) | |
157 (dired-activate-extent g-x-extent '(s x space) 'dired-g-x) | |
158 (dired-activate-extent o-r-extent '(r space) 'dired-o-r) | |
159 (dired-activate-extent o-w-extent '(w space) 'dired-o-w) | |
160 (dired-activate-extent o-x-extent '(s t x space) 'dired-o-x))))) | |
161 | |
162 (defun dired-permissions-highlight () | |
163 (message "Highlighting permissions...") | |
164 (save-excursion | |
165 (goto-char (point-min)) | |
166 (while (not (eobp)) | |
167 (and (not (eolp)) | |
168 (dired-make-permissions-interactive)) | |
169 (forward-line 1)) | |
170 (message "Highlighting permissions...done"))) | |
171 | |
172 (provide 'dired-chmod) | |
173 | |
174 ;; dired-chmod.el ends here. |