Creating an alias for emacs in read-only mode on L

2020-08-03 08:25发布

问题:

Just so you know this is my first ever post.

Basically, I am trying to put in an alias (or something) in my .tcshrc file so that I can open a file in emacs read-only (without having to type the blurb below everytime). I found this - https://superuser.com/questions/204236/how-can-i-open-a-file-read-only-from-command-line-with-emacs-vi-vim - but since tcsh does not support functions (I think) I cannot use this method.

The command line text for opening emacs in read-only format is this:

emacs FILE_NAME --eval '(setq buffer-read-only t)'

Any ideas?

Thanks P.

回答1:

Quotes and parens in tcsh aliases can be problematic, so --funcall toggle-read-only in Satish's answer is probably easier to use than --eval. To insert an argument after the filename, you can use the \!:1 expression for the first argument:

alias emacs-ro emacs \!:1 --funcall toggle-read-only


回答2:

I would create script called emacs-ro and place in your PATH

#!/bin/bash
emacs "$@" --funcall toggle-read-only

Or you can use your options too.

--eval '(setq buffer-read-only t)'


回答3:

As per Satish's answer, but with the suggestion that if you're using Emacs >=24.3 you can and should use read-only-mode instead of toggle-read-only, The latter will still 'work' but is now obsoleted.

#!/bin/sh
emacs "$@" --funcall read-only-mode