tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chmod after file write


From: Ted Zlatanov
Subject: Re: chmod after file write
Date: Fri, 11 Oct 2002 17:42:54 -0400
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-redhat-linux-gnu)

On Fri, 11 Oct 2002, address@hidden wrote:
> How about writing a function that looks up the right modes in an
> alist and then invoke that function from after-save-hook?  Would
> that work?

I found this:

http://www.stud.ifi.uio.no/~pok/download/buffer-file-modes.el

which did not work for me, but did give me ideas.

I don't know enough Lisp to write something that tries string matches
through the keys of an alist.  buffer-file-modes.el has a function to
do this, but it seems wrong to me that it should take this function:

(defun pok-search-alist (string alist)
  "Search through an alist for a string, return the cdr if string
is found as a car.  Otherwise return nil."
  (do ((l alist (cdr l))
       (str (car (car alist)) (car (car l)))
       (val (cdr (car alist)) (cdr (car l))))
      ((or (null l) (string-match str string))
       (if (string-match str string)
           val
         nil))))

to look up a string match in an alist.  The author's use of decimal
instead of #Oxyz to enter octal numbers was a hint to me that maybe
his Lisp is not optimal :) Not to slight the buffer-file-modes.el
author, only that I hope someone can help with a better solution.

> Let us know your findings, it's an interesting subject.  (I hope the
> other readers here won't mind :-)

The solution I have right now:

(defun tzz-write-file-hook ()
  "Do personal setting of file permissions"
  (let ((permission #O644))
    (when (string-match "lifelogs.*html" buffer-file-name)
      (message "set permissions of %s to %o" buffer-file-name permission)
      (set-file-modes buffer-file-name permission)))
  nil)

(add-hook 'after-save-hook 'tzz-write-file-hook)

works great for my particular case, and I don't mind the extra chmod
command execution when I save the file.  But I would love to see how
this can be generalized, like buffer-file-modes.el tries to do.

Sorry that this is a little off-topic for tramp.

Thanks
Ted





reply via email to

[Prev in Thread] Current Thread [Next in Thread]