reddit / emacs

How to create, edit, and save files using Emacs? My buffers are read-only.

ApexYenzy · 2022-12-18 16:11
If I run the command emacs helloWorld.java It creates a buffer but it's in read only mode, if I do c-x c-q which changes it so I can write the file I cannnot save the file, because it says I do not have permission. I would like it to whenever I type that command, it opens a buffer/file that I can write, save, edit and execute. In my most recent CS class we used emacs and we could just type emacs whateverFileName.java and it would create a file we could edit and save and exe if we compiled with javac and java. How do I do this with my personal emacs?
redblobgames · 2022-12-18 16:15
It might be a permissions problem. Try `emacs .` and it should open a directory listing. 1. Look at the `.` entry on top, and its permissions. I think you need it to start with `drwx`. This controls whether you can create/delete files in this directory. 2. Look at the other files, including `helloWorld.java` if you have that. It should start with `-rw`. 3. Look at the owner of the directory and files. It should be you, and not someone else.
ApexYenzy · 2022-12-18 16:25
It does start with drwxr-x- - -
ApexYenzy · 2022-12-18 16:36
also, when I'm in emacs and do "m-x chmod" on the file it says "Doing chmod: operation not permitted"
podtatranec · 2022-12-18 17:26
Are you sure you own the current directory then? It simply seems like you don't have permissions to the directory where you are attempting to create the files.
FrozenOnPluto · 2022-12-18 19:42
Details .. which OS and environment? Windows .. which version. Cygwin, native, linux compat mode, vm? Mac? Linux.. which? So many possibilities that no one can really help too easily. But yeah you (and thus your emacs) is lacking permissions by the sound of it so probably a host OS issue. What path are you working in? Emacs from a package or you compiled from source yourself?
ApexYenzy · 2022-12-18 22:31
I mean, it’s my pc so I assumed I own the dir, but it’s a dir inside my home
ApexYenzy · 2022-12-18 22:35
OS - Linux, Ubuntu 22.04, I don’t know the answers to the last 2 questions
hhoverton · 2022-12-18 23:59
how did you install emacs?
ApexYenzy · 2022-12-19 01:57
Thought the terminal, I looked up a guide
hhoverton · 2022-12-19 02:33
What was the command? Through the terminal doesn't really help figure out how you installed it
ApexYenzy · 2022-12-19 03:57
I am stupid, bear with me sudo add-apt-repository universe sudo apt update sudo apt install emacs
podtatranec · 2022-12-19 07:47
You seem to be new in Linux world. We don't make assumptions. We check. Who owns your current directory? There are many other system users + root who could actually own it for one reason or another. You could have copy-pasted some stupid command from the web or some other comment elsewhere and changed ownership of files etc. This is quickly turning from an Emacs question into a more generic Linux/Unix question though. Basically make sure you can run `touch filename` in the directory before you try to do anything with Emacs in it.
copperbranch · 2022-12-19 09:45
Since you’re struggling to check permissions, a quick try would be `emacs ~/fakefile.java` to create something in your home folder, where you very likely have permission
copperbranch · 2022-12-19 09:47
But you should read a bit about permissions in Linux, how to check it and set it. It’s not too complicated. You can check this page: https://wiki.archlinux.org/title/File_permissions_and_attributes The arch wiki is a good source for linux things, no matter what distro you use.
FrozenOnPluto · 2022-12-19 20:27
People are downvoting, but give the guy a chance; you're asking a code question, so people tend to assume you're technical .. but folks can be young, or non-geeks, or just learning for fun, or whatever.. coders aren't (amazingly) born from geek pea pods :) Anyway, the 'path' is the location drill down to where you are; like, are you in your homedir, or in a system dir; on Windows, things like C: (drive) or C:\\ (root path on drive C) or C:\\windows\\something (a system path) .. on Unix-like systems, stuff like \~ maps to your home dir root, or /home/yourname likely on most modern Unix-likes .. but stuff like /proc is super not yours to play in unless you know what you're doing or have permissions. So this is why I mentioned path .. if you're in \~ or \~/some/thing, you likely shoudl have permission to write a file there, or have the capability to get that; like, you could create a subdirectory \~/work and make it read only by mistake; or you could create \~/mydir/myfile and make myfile read-only, and then need to overwrite its permissions to write to it.. theres lots of ways to hang yourself; its just usually if you're clever enough to install linux, or make directories and fiddle with permissions to hanfg yourself, you'd also know how to unhang yourself :) Still, you're asking Linux or Unix questions, not Emacs ones, fyi; this same problem would be for any tool. So you can youtube or google how linux or unix permissilons, like file permissions or directory permissions, to learn how those work, so you can unhang yourself, or know how to set things up. TYhere are both GUI ways to do it (using a pretty file browser clicky click), or command line at the shell; stuff like "chmod ugo+rwX myfile" from the same path (same directory) as the file you're trying to write to, or of tyhe direcotry a level up. chmod being a way to set permissions, and ugo being shorthand for 'user, group, and other' and +rwX meaning "add read, add write, add pass through a direcotry if its a directory'. Look up that stuff.