tags:

views:

76

answers:

4

On Linux, they 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, I type C-h f isearch-forward and click on the link isearch.el from the help to get to the definition of the function, and while I am reading its definition, I press C-h or C-c many times, but I set Caps Lock as another Ctrl key, so sometimes it happens that I release Caps Lock too early, in which case C-h or C-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 C-x s.

What is a good way to protect the built-in el files from me on MS Windows?

+3  A: 

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 .
Trey Jackson
in a cmd.exe prompt, cd to the \emacs\lisp directory, and `find -name "*.el" -exec attrib +R {} ;`
Cheeso
+1  A: 

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.

huaiyuan
A: 

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.

Cheeso
I just used this again. I wish I could upvote me.
Cheeso
+1  A: 

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
RamyenHead