On Thu, 10 Oct 2002, [EMAIL PROTECTED] wrote:
> Very often I need to do a chmod for specific files after saving
> them, for instance I would like a rule that all files matching
>
> .*lifelogs.com:.*html
>
> should have permissions "a+r" set after writing. I don't want to
> set the umask open for all new files on this host, so I can't do it
> through the shell variables. Is there a hook I can use in tramp,
> and a command I can run in that hook to do what I want?
>
> dired-do-command works, but I can't find a way to invoke it
> automatically; it currently takes its arguments from the dired
> buffer which is not what I want. I want this to be automatically
> done for all files I save with tramp.
I had a request for the Lisp code - here it is, if anyone else is
interested. I hope it's useful to others.
Ted
-------------------------------------------------------------------
;; automatically set permissions from the file tzz-permissions-file
;; Example:
;; all file saves of buffers whose name matches "cgi.*html" or
;; "cgi.*pm" are mode 644 (rw-r--r--), all "cgi.*pl" are 755
;; (rwxr-xr-x)
;; contents of tzz-permissions-file:
;; 644 cgi.*html
;; 644 cgi.*pm
;; 755 cgi.*pl
(setq tzz-permissions-file "~/.permissions")
(setq tzz-write-file-verbose t)
(defun tzz-read-permissions()
"Read the permissions file"
(let ((permissions-file-name tzz-permissions-file)
alist)
(if (file-readable-p permissions-file-name)
(with-temp-buffer (insert-file-contents-literally permissions-file-name)
(while (re-search-forward
"\\([0-7]\\{3,4\\}\\)[ \t]+\\(.*\\)\n" nil t)
(setq alist (cons (cons (match-string 2)
(match-string 1))
alist)))
alist)
nil)))
(setq tzz-permissions-alist (tzz-read-permissions))
(defun tzz-write-file-hook ()
(interactive)
"Do personal setting of file permissions"
(dolist (cell tzz-permissions-alist nil)
(let ((permission (string-to-number (cdr cell) 8))
(regex (car cell)))
(when (string-match regex buffer-file-name)
(when tzz-write-file-verbose
(message "setting permissions of %s to %o" buffer-file-name permission))
(set-file-modes buffer-file-name permission)))))
(add-hook 'after-save-hook 'tzz-write-file-hook)
_______________________________________________
Tramp-devel mailing list
[EMAIL PROTECTED]
http://mail.nongnu.org/mailman/listinfo/tramp-devel