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.
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
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)'
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