Currently, whenever I open a new file with emacs (I work terminal only) it opens it within a new workspace. That can be quite annoying for me as initially when I start working, I open my project which has some init stuff (lsp-go) that takes a few minutes (monorepo). After that, I would like that whenever I open a new file (from the terminal again) that it uses the same workspace as prior so that it does not have to reinitialise everything (+ I would like to keep my buffers within the same workspace).
Here are some of my aliases:
alias estart="emacs --daemon"
alias estop='emacsclient -e "(kill-emacs)"'
alias e="emacsclient -nw"
My usual workflow is:
Start the server e.g. estart
Open the project e . (this will trigger lsp to load its stuff)
Later on, I open another file (could be anywhere even outside the project) e someFile
Note, I use doom emacs if that's of any use
Related
Most of the time I use the gd command then I have to browse the file manually in a new terminal tab, because I still need to leave open the previous file.
It would be just a bit useful to be able to open the definition in a new tab, of course, I'm just wondering if this is possible and how to configure it, probably mapping a new command in the nvim config file?
This is how I'm mapping the gd command:
nmap <silent> gd <Plug>(coc-definition)
You shouldn't open in new terminal tab, because this means you'll start a new vim process instance and will launch a new language server process that you use. If you're using some other vim remote plugins, they'll be loaded again.
You can set "coc.preferences.jumpCommand": "tabe" in your coc-settings.json, this will open in vim tabs.
I want to open all files under /var/log/my_program/ in my current open workspace. To be clear, I want to open the files from this directory while keeping the files that are already open in my current workspace open as well.
e.g. if I have ~/hello-world.html open, I would like to open /var/log/my_program/error.log and /var/log/my_program/access.log in the workspace as well, having a total of 3 files open at the same time in the same window/workspace.
if I run code /var/log/my_program/* it will open up a new window with all of the files open from that directory. i.e. hello-world.html will be in one window and error.log and access.log will be in a new window
if I run code -r /var/log/my_program/* it will overwrite my current workspace with the files from that directory. i.e. hello-world.html will no longer be open in any window, and error.log and access.log will be open in my original workspace window.
I want to be able to keep the state of my current workspace AND open the files from the /var/log/my_program/ directory. i.e. I would like hello-world.html to stay open in the workspace AND have error.log and access.log open as well.
I would like to add that this is just a simplified example of what I am trying to do. I understand it would be easy enough to just open these two files easily in the command line, but the actual files in the dir I want to open could be several and all with timestamps in their names, so I cant easily open them by name
Is this possible? Thanks for any help!
EDIT:
I am really looking for a solution using the CLI. I am running a command similar to rm /var/log/my_program/*; systemctl restart my_program; code /var/log/my_program/*. This is so the dir doesnt get full of old log files, and I can see the new log files opened after I have restarted the process for my_program
The reasoning for all of this is to make my debugging routine less cumbersome, e.g. without mouse clicks or gui interaction
In VS CODE itself there is a keyboard shortcut that might be helpful:
ctrl + r
Which will open a drop down of folders.
Once you arrow down/up to the desired folder, you have two options:
Click enter to open the new folder instead of the current workspace, or
ctrl + enter to open a new folder in addition to the current open workspace
If I understand what you are trying to do correctly, you want to use the --add argument. You can run code --reuse-window --add <path> to open the folder at <path> in the current workspace. The shortened version would be code -r -a <path>.
I have my emacs.d folder located at:
C:\Users\<loggedin_user>\AppData\Roaming\.emacs.d
In this folder, I have my init.el file but it is not being picked up by emacs.
Is there another step I am missing, do I need to set an environment variable or something?
When I enter C-x d ~/ RET I end up at
C:\Users\<loggedin_user>\AppData\Roaming\
If I move the init.el file there, it is still not picked up. I have a deliberate error in the file that is not causing emacs to crash when it is opened.
Most likely you have an old ~/.emacs file somewhere else which Emacs ends up using in preference to the other one.
You probably want to check the value of user-init-file which will tell you which file Emacs ended up using as "the ~/.emacs file".
I suggest you report this as a bug, requesting that when several files are found as possible init file, Emacs should not just pick the first and ignore the others but should at least emit a warning about the fact that it ignored the others.
This is tricky on Windows 10 but I solved since I was suffering from same issue.
I created an Environment Variable called HOME with the path C:/user/<username> in the box "User variables for " create a new one
Just open with double click any file that is by default opened with Emacs and it will take few seconds to load then take changed on the init.el
create an init.el with just one line of code like:set-background-color "honeydew"
to test this, first before doing something more complex.
Hope That It Helps!
On Windows, Emacs is started with some Properties defined, found when you right-click the executable on your windows system. There you can define the
execution-directory, e.g. "C:\Users\loggedin_user\" (in parantheses)
where emacs executes
and looks for the .xemacs (.emacs) directory, where it find its init.el. (I had to create an .emacs File in my Windows Home Directory, which is defined in the Windows HOME Environment)
And where you can define the startup instructions (like (setenv "HOME" "c:/Users/Username/") ) etc.
If you configure that, the next time, emacs starts from the directory, you defined, with the initialisation-file
Windows 10 and Emacs 27.1 could not find .emacs.d: one more possibility, in my case %HOME% was set like HOME=%HOMEDRIVE%%HOMEPATH%. This redirection seems not to work and emacs was using literally C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% for searching .emacs.d. I did not dare to edit %HOME% but created link:
C:\Users\username> cd %HOME%
You perhaps need to remove some files in C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% which emacs already created.
Create link:
C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH%> mklink /d .emacs.d ..\.emacs.d
Suppose that the file A.txt is already opened with GNU-emacs, but I don't notice it, so I try opening it (again) with
emacs A.txt
Instead of just showing the already-open window it opens a second one!
(This is of course annoying, since I will end up with 2 conflicting versions.)
How can I avoid this (under ubuntu) ?
Command emacs starts a new instance of the application.
What you are looking for is emacsclient which connects to an existing emacs instance and tells it to edit the file.
You need to start the server first though.
I want to keep emacs open most of the time, and then whenever I open a text file, python file, etc (from nautilus/finder), I want it to open as a new buffer in my current emacs instance, rather than starting a new instance.
I tried following this guide:
I wasn't really sure about what to do with the file, but what I tried was copying it to /usr/bin/emacs_openfile, adding #!/bin/sh to the first line, and running chmod +x emacs_openfile
However, it doesn't work for me and just opens a new instance, even though I was able to associate text files with this program.
On a sidenote, I set emacs as the default editor using this.
You want emacs client.
Basically, set emacsclient as your default editor, and add (server-start) somewere in your emacs config.
There needs to be a running Emacs instance for emacsclient to work, but if it's a hassle it's possible to have a headless Emacs launched at login.
Did you start server in emacs? Make sure that you add (server-start) to your .emacs or do M-x server-start from an existing EMACS session.
Conceptually, it's really easy, just do emacsclient file-name on the command line or where you name the program.
Just for your information, If you are using GUI version on Mac, the dir os emacsclient is below:
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient