When I @edit 2 + 2
, I can change the source code of addition. That seems dangerous. In fact, I only use @edit
to inspect source code, to learn how a library works and things like that. I almost never do any edits. Is there a way to make sure @edit opens source files in read-only mode?
Maybe use @less 2+2
instead just to view the code?
How would it do that? @edit
just opens the file. If you editor supports command line arguments to open files read only, then call it like that, otherwise I don’t see how this would work.
Some editors (eg Emacs) allow making buffers read-only, or you can do a chmod -R
on your julia source to prevent modification.
Perfect, I did
ENV["JULIA_EDITOR"] = "vim -R"
and then @edit 2 + 2
is read-only. Thanks!
Too bad Sublime Text doesn’t seem to have a command line flag for read-only mode.
This works… but it is very hard to read without syntax highlighting.
Horrible hack of the day:
#!/bin/bash
FILE=$1
ALT=${FILE}_readonly
if [ -f $ALT ]
then
echo "$ALT already exists, not overwriting" && exit 0
fi
cp -n $FILE $ALT
chmod a-w $ALT
$EDITOR $ALT
rm -f $ALT
Makes a copy, makes that read-only for good measure, opens it in the editor, then removes it when done. Use at your own risk — I am the world’s worst bash programmer, there is probably some corner case that wipes your hard disk and makes your computer explode. (You can probably write a better one with 5 minutes of googling.)