You are not logged in.
I am currently using emacs from the command line with AUCTeX to create LaTeX documents. I finally got the formatting just how I like it and would like to save a .tex file as a template. I created an alias that opens this file in emacs with the command "emacslatex". I would like to make this template.tex file read only, yet I can still edit the buffer and save as a new file. I could just do this by saving with C-x C-w, but I am so used to doing C-x C-s to save files that I slip occassionally. In vim, editing a read only file just shows a warning at the bottom of the screen that I will not be able to write this file, but then I am able to edit just fine save as a new file name. How can I get similar functionality with emacs? Googling and looking through the emacs documentation has turned up no results, unfortunately. Perhaps AUCTeX does something I am not aware of?
дɭɭɑӎɠїɾ
Offline
Why not make your "emacslatex" command copy the template to a new file and open that? Or make it open a buffer associated with no file then copy the text into it.
Offline
C-x C-q.
You can also tell and enable/disable from the mode line.
In my current buffer it shows:
U:@%*
meaning
Unicode|undecided end-of-line style|emacsclient frame|read only|modified buffer
--Rasmus
Arch x64 on Thinkpad X200s/W530
Offline
Why not take something like this, and put it in /usr/bin- then when you run emacslatex new.tex, you get your template in a new editable file in a name of your choice.
#!/bin/bash
cat /path/to/template.tex > $1
emacs -nw $1
Offline
Why not make your "emacslatex" command copy the template to a new file and open that? Or make it open a buffer associated with no file then copy the text into it.
How exactly would I do that? The command currently run when I type in "emacslatex" is:
emacs -nw +33:32 /home/agi/Documents/template.tex
дɭɭɑӎɠїɾ
Offline
Ok I tried your script, greg, and every time I run it an extra blank buffer is opened along with my .tex template (which opens correctly). How do I make this extra blank buffer not open?
I commented out the alias for emacslatex in my .zshrc and sourced it
дɭɭɑӎɠїɾ
Offline
Odd, I don't get an extra blank buffer when I run it on my system...
Offline
The top buffer has template.tex in read only mode (so I STILL can't edit it), while the bottom buffer has new.tex completely blank.
How to I make Pank's solution (C-x C-q) work for all read-only documents? What do I put in my .emacs file?
дɭɭɑӎɠїɾ
Offline
pauldonnelly wrote:Why not make your "emacslatex" command copy the template to a new file and open that? Or make it open a buffer associated with no file then copy the text into it.
How exactly would I do that? The command currently run when I type in "emacslatex" is:
emacs -nw +33:32 /home/agi/Documents/template.tex
I figure you'd ideally want to use emacsclient to call a function that copies it into a new buffer. Something like the following.
; In .emacs:
(server-start) ; If it's not there already.
(defun create-tex-from-template ()
(let ((b (generate-new-buffer "TeX-template")))
(switch-to-buffer b)
(tex-mode)
(insert-file-contents "~/test.file")))
# In emacslatex:
emacsclient -e '(create-tex-from-template)'
There may be a better way to write it, or you may want to start a new Emacs and call that function in it. Or you might like to let it take an optional file name argument.
Last edited by pauldonnelly (2009-07-31 21:24:20)
Offline