emacs can't open files outside current directory - emacs

So here is an interesting error...there is a particular folder on my desktop (hdrive, connected to a university-wide backup system, was set up automatically by IT) where emacs has difficulty opening files. In some directories within hdrive emacs can't open files above the current directory. For example,
cd ~/hdrive/directory/
emacs ../another_directory/file
gives the error message
emacs: `get_current_dir_name' failed: No such file or directory
I get the same error if instead I try
emacs ~/hdrive/another_directory/file
The files themselves are not missing and not corrupted, as using cat in place of emacs in these commands works fine. And I don't get this problem with all directories in hdrive - sometimes even a directory with this problem will have a subdirectory without it - but the directories with this problem are consistent.
There is no .dir-locals.el anywhere in hdrive, so that can't be messing things up.
Any ideas?

For me, this problem occurred because I was standing in a folder that I had deleted and recreated in another terminal (git issue).
Navigating away from the folder and back again made emacs and/or the terminal understand which folder I was actually in, and I could start emacs again with no problems.
I doubt this will solve the specific issue the questioner had, but anyone else ending up on this page through a google search on the error message might find my answer useful.

Related

Renaming files doesn't take effect in VScode while using WSL2

I have a very annoying problem in my VScode setup.
I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.
For example:
I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.
Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.
So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.
The file is there in my folder but when I click on it, I get
"Unable to open Mainheader.js - File not found"
So I try to create it then I get this error:
Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set
Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...
Any help would be appreciated. I can't really work like this.
I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.
I did find this work-around though:
Open a new VS Code window. (I'd recommend closing any VS Code window that had
your project directory open.)
Create a duplicate or copy the contents of the problem file so you don't lose
your code.
Delete the problem file.
Now create the file again using VS Code. Go to File > New Text File. Next paste
in your code.
Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.
Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.
Hope this work-around works for you!
EDIT 09/20/2022
Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.
How to run VScode in sudo mode in WSL2?
You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.
Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
My default config looked like this yours may be different:
[automount]
options = "metadata"
add
[automount]
options = "metadata,case=dir"
Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config

Atom - Unable to save file: Permission denied (Windows)

I've been a long time user of notepad++ and I enjoy it a lot, but a friend recently recommended me to use Atom, so I gave it a try. However, when I try to save anything in my project folder (or any file at all), I receive this message that I am unable to save file: permission denied.
I've tried typing the command sudo atom /path/to/file in my PowerShell for Windows, but I get the following message:
I understand that sudo is a Linux-based command and thus would not work in a Windows environment but would there be an alternative route to get Atom working on my machine?
Thanks a lot!
The files were made "Read Only" somehow (maybe your anti-virus software or something, who knows...).
Solution:
Go to the folder in the Explorer, highlight all of the files in your project. Right click, open the properties. Deselect "Read-Only" and push ok. When it asks if you would like to apply to only the selected files or also to the files in any sub-folders, click yes if you need to.
This should fix your problem.

spacemacs warning: directory is unsafe

I received this error whenever I start spacemacs
error: The directory `/var/folders/2g/9ndwhk353n97d5vgcqdpsz580000gr/T//emacs504' is unsafe
It seems like no one has had this problem before.
It is probably due to I did chflag on some directory sometime ago, but I couldn't remember what I did exactly..
I'm on Mac and my spacemacs is in the latest version.
Not seen that specific error before, but Emacs tends to complain about directories being 'unsafe' when someone other than the user currently running Emacs owns or has access to the directory.
See this other Stackoverflow question for a Windows example:
Emacs - Error when calling (server-start))
In your case, I would just delete the emacs504 folder, as emacs probably will recreate it with the correct perms since it's in /var/.
I got this error for /tmp/emacs... directory for using Spacemacs based on Cgywin Emacs 26.1. Just removing the directory and then restart of emacs did not solve the problem for me. But simply changing the access rights for the directory using chmod g-rwx /tmp/emacs... did the job.

How to change the virtualenv for emacs virtualenv.el

I tried to use virtualenv virtualenv.el file posted here.
But I set the wrong directory. (Moreover, it seems that it requires I put my virtualenvs in the .virtualenv directory, not in the disparate directories where I've written them on my machine.)
How can I change this back? Now when I run M-x virtualenv-workon I don't have the same intro prompt I had the first time.
Update
Following the note left in the comments and the documentation, I added the following file to my project folder:
/home/fred/projectname/.dir-locals.el
this contains the following:
((nil . ((virtualenv-workon . "venv")
(virtualenv-default-directory . "/home/fred/projectname/venv"))))
However, still when I open emacs in my project directory and type M-x virtualenv-workon it only finds local (default) not venv. What am I missing?
I just had the same problem. I know the post is older and virtualenv.el is depricated, but in case anybody else also stumbles across this:
When you run M-x virtualenv-workon for the first time, it creates an entry in your .emacs file. The file should be found in your home directory. The entry is under custom-set-variables and is called virtualenv-root. You can open the file and adjust the path manually to whatever location you would like.

Emacs Tramp unable to open directory at times

Normally I am able to use tramp just fine to edit files and browse through the remote file system through SSH. Though at seemingly random times I would lose the ability to browse remote folders in emacs.
I get the error message:
Wrong type argument: number-or-marker-p, //DIRED-OPTIONS//
I've tried doing a clean reinstall of emacs without any customizations and the error still happens.
Also sometimes the error happens after browsing 1 or 2 directories while other times I'm able to do five or six directories before the error will appear.
Edit:
I'm using Emacs 23.3 running on OS X 10.6.8
Edit 2:
While I'm still going through the tramp debug log A couple of other pieces of information.
After the error I'm still able to use tramp of open and save files, just not view directory listings.
It seems to happen only when I save to a directory that is version controlled using git.
In the debug log the directory contents are listed out but it is not being outputted to the user
The directory listing inside the debug log show ^M (I usually notice this in the emacs info bar when editing files that have been versioned in git) even when I try to access a non-version controlled directory
The message is useless by itself. You should try to obtain more traces on the tramp behavior in order to find where is the issue. See the Traces and Profiles Section of the TRAMP User Manual.
Sorry to not help more but with another release on another platform…
Update:
Put the following in your emacs file
(require 'tramp)
(setq tramp-verbose 10)
(setq tramp-debug-buffer t)
Then, use tramp. Now, You should have a *debug tramp/method hostname* buffer.
I found out that this happens when I enable:
(setq-default dired-omit-mode t)
But for now I don't know how to make it work with this mode