开发者

How to protect built-in el files from being accidentally edited on Windows

On Linux, the built-in el files are all read-only, so no problem.

But on MS Windows, what happens is like this:

  • I get curious about the definition of the command isearch-forward, so I type ctrl-hf isearch-forward and click on the link isearch.el from the help to get to the definition of the function.
  • While I am reading its definition, I press ctrl-h or ctrl-c many times, but I have previously set Caps Lock as another Ctrl key, so sometimes it happens that I release Caps Lock too early, in which case ctrl-h or ctrl-c becomes inserting h or c.
  • Sometimes I notice that and undo it, but sometimes I don't notice it, and I even save them all with ctrl-xs.

What is a good way to protect the built-in el files from me on MS W开发者_JAVA百科indows?


Change the permissions to be read-only.

M-x find-function isearch-forward RET
M-x dired RET
% m . RET
M -w RET

The sequence will open up the file isearch.el, then use dired on its directory. At which point you mark all the files, and then change permissions to be read only.

You'll also want to do it for the sub directories. So whip up a macro and run it until you're done.

Starting in the lisp dired buffer (the one you created up there), go to the first file (right below . and ..), and begin:

C-x (
>
RET
% m . RET
M -w RET
q
C-x )

There, you have defined a macro to go to the next directory, enter it, mark all its files read only, and leave the directory. Now run it several times (20 for Emacs 23.1).

C-u 20 C-x e RET

And you're done.

If you have a cygwin shell, it'd be a lot easier to just do

M-x shell
cd c:/Program\ Files/emacs-23.1/lisp/
chmod -R -w .


Take a look at Directory Local Variables. This should meet your need:

(dir-locals-set-class-variables
 'read-only '((nil (buffer-read-only . t))))
(dir-locals-set-directory-class
 source-directory 'read-only)

Change source-directory accordingly.


I decided to make el source buffers read only (using the variable buffer-read-only) on load.

(defun my-make-some-read-only ()
  (if (and buffer-file-name
       (or
        (string-match-p "/emacs/lisp/" buffer-file-name)
        (string-match-p "/EmacsW32/lisp/" buffer-file-name)))
      (setq buffer-read-only t)))
(add-hook 'emacs-lisp-mode-hook 'my-make-some-read-only)

If the above code is in dotemacs, buffers from el files like following are set as read only.

c:/Program Files/Emacs/emacs/lisp/emacs-lisp/lisp-mode.el
c:/Program Files/Emacs/EmacsW32/lisp/w32shell.el


Open a cmd.exe prompt, and do this:

c:\> cd \emacs\lisp
c:\emacs\lisp> find -name "*.el" -exec attrib +R {} ;

You need a find.exe utility. I use the one from UnxUtils.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜