# @edit read-only?

**URL:** https://discourse.julialang.org/t/edit-read-only/7044
**Category:** General Usage
**Tags:** question
**Created:** [November 13, 2017, 3:05pm UTC](https://discourse.julialang.org/t/edit-read-only/7044 "2017-11-13T15:05:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 13, 2017, 3:05pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/1 "2017-11-13T15:05:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [November 13, 2017, 3:22pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/2 "2017-11-13T15:22:46Z")

</div>

Maybe use `@less 2+2` instead just to view the code?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 13, 2017, 3:29pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/3 "2017-11-13T15:29:36Z")

</div>

> [@e3c6](#):
>
> Is there a way to make sure `@edit` opens source files in read-only mode?

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.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 13, 2017, 3:52pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/4 "2017-11-13T15:52:06Z")

</div>

> [@Tamas\_Papp](#):
>
> If you editor supports command line arguments to open files read only, then call it like that

Perfect, I did

```julia
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.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [November 13, 2017, 4:06pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/5 "2017-11-13T16:06:32Z")

</div>

> [@ScottPJones](#):
>
> Maybe use @less 2+2 instead just to view the code?

This works… but it is very hard to read without syntax highlighting.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 13, 2017, 4:19pm UTC](https://discourse.julialang.org/t/edit-read-only/7044/6 "2017-11-13T16:19:52Z")

</div>

> [@e3c6](#):
>
> Too bad Sublime Text doesn’t seem to have a command line flag for read-only mode.

Horrible hack of the day:

```bash
#!/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.)
