Emacs modes/functions and xmonad - emacs

So I'm wondering if it's possible to take XMonad's ability to shift certain applications to specific workspaces a step further and apply it to specific modes/functions of Emacs?
For example I have mod+shift+u bound to spawn "emacs -f mu4e" which runs drops me into mu4e, the mail mode/function that i'm using to read mail. I'd like to bind that to a specific workspace instead of just opening in whatever workspace i'm in at present.
The problem (or not really a problem) is that I use Emacs extensively (mail, irc, etc.) and i'd like to have the specific modes/functions associated with workspaces and not have to move them there manually. I've looked at many XMonad.hs configurations and it seems that a huge majority use apps like pidgin, xchat, etc. and so it's trivial to setup the workspace association.

Maybe you could specify a specific window title for your Emacs frame and use it to setup the workspace association (instead of the window class, which I assume you'd use for pidgin or xchat)
emacs --title "mu4e" -f mu4e
I don't know xmonad, but if it is not able to provide workspace associations based on windows titles, you could use a tool like wmctrl instead. For example (assuming you want to move to the desktop number 4):
wmctrl -r mu4e -t 4

Related

Project switching in emacs

I would like to associate sets of buffers/files in emacs with different projects, and switch from one to other. This would involve closing all the buffers associated with the present project and open the files corresponding to the switched-to-project. I tried setting up desktops using bookmarks+ as suggested in https://emacs.stackexchange.com/questions/315/using-desktop-for-basic-project-management but all buffers remain open. I also tried setting up workgroups using workgroups2 (https://github.com/pashinin/workgroups2), but had similar issues. Is there an existing emacs package that could be used for this?
There is an excellent package called Projectile that does exactly what you describe and more.
Alternative suggestion
I recommend that you don't look to emacs to manage buffers, frames, and editor state separately across projects.
Instead, use a desktop manager and create separate desktops for each project. This works well because not only can you have separate emacs instances (that you can be sure are truly separated), but you can also have separate web browsers open to documentation or other project-specific applications that collectively get swapped in and out when you switch between projects.
You say, "I tried setting up desktops using bookmarks+ as suggested in using-desktop-for-basic-project-management but all buffers remain open.".
I guess you mean that switching to a desktop does not kill buffers that existed before the switch. Not by itself, it doesn't. How can it guess which such pre-existing buffers you want killed?
Clearly you do not want to kill all buffers that existed prior to the desktop switch.
To get the behavior it seems you want, you would need to somehow decide, and specify, which such buffers you would like killed. You could, for example, choose to kill all that have a certain mode (perhaps using desktop-buffer-mode-handlers).
With Bookmark+ you can have bookmarks that do more than one thing. In particular, here, you could create a sequence bookmark that chains together (1) a function bookmark that kills all of the buffers you want to kill and (2) a desktop bookmark.
Or you can perhaps make use of desktop-after-read-hook or desktop-buffer-mode-handlers to do some cleanup.
(But it sounds like you have not really thought through exactly what behavior you want with respect to buffers that you do not want to "remain open", so that you can specify it clearly. If you can specify it then you can probably implement it fairly easily, using either desktop hooks or bookmarks or both. Just a guess.)

How to use Emacs as multiple IDEs with EVIL running in them all

Im just starting to look into Emacs as a IDE. There are lots of articles about how to setup Emacs as an IDE for languages XYZ. Most of these articles talk about how to switch content in your emacs.d. However this would only work if you use Emacs for one language?
Say for example I want to use Emacs with Clojue, Javascript and Python. For Clojure i want to use LiveMode and for Javascript i want to use some other mode and the same for Python. All highly specialized with a background repl running. How would I go about setting emacs up for this and what if I would like to use for example EVIL mode on all the IDE:s? Would it be possible to switch IDE setup at runtime depending on file ending or do i have to restart Emacs loading different settings each time?
Emacs allows to use so-called modes with files, e.g. python-mode for Python files etc. Automated enabling of modes for a specific file is either happening through file-local special variables or via associations of file-types via auto-mode-alist.
Modes actually provide these "special" settings you are talking about. If you want to add a special additional behavior in some mode, you typically add the required setup functions in the so-called mode-hook.
It might happen you run into incompatibilities between various extensions or modes, but this is a pretty rare case.

Run Specific Plugins for each Emacs Instance

Is it possible to have only certain plugins run when first starting emacs?
Let's say I develop in Python and also in Ruby. So I want to have one emacs instance running with Python plugins and another running Ruby plugins.
What I'm imagining is I can call rb-emacs or py-emacs from the command line.
So I think part of my solution lies here
http://stackoverflow.com/questions/2112256/emacs-custom-command-line-argument
And then I can alias the emacs call with the custom switches to one of the above
But then, how can I associate a specific plugin with a specific switch?
Am I on the right track with this? Or should I be doing something else entirely?
Edit:
Since my problem does not seem to be clear, I'll try to reiterate here. I'm not worried about long loading times. I'm worried about potential conflicts between plugins. I've used emacs before but only on a basic scale. Now I'd like to go more in depth with plugins. Though I don't fully understand how the plugins work.
Say I have a plugin (or two or three, I don't know how many it might be) for each language I code in. Won't those conflict with each other? Also, I don't want views / windows that are unneeded for that particular language.
You'll just need a different init file for each of your Emacs instances. Then you can create shell aliases for opening Emacs with those init files.
From the Emacs Wiki:
Start Emacs with a specific init file: emacs -q -l ~/my-init-file.el
Then you'll just set up a shell alias like:
alias rb-emacs=emacs -q -l ~/.rb-emacs-init.el
But why do this with separate Emacs processes? If you're concerned about the startup time, you can use lazy loading of packages or Emacs Server with Emacsclient.
I'm voting for "doing something else entirely", but I'm not 100% sure what the problem you're trying to solve is.
In general you can use mode hooks, eval-after-load, and autoload to ensure that you only load a particular elisp library when it is required.
If your problem is that you're forcibly loading everything and it takes too long, then you need to change your code so that you only load things when necessary. See OptimizingEmacsStartup.
If your problem is that you are setting global values for variables that need to have different values for different projects, then you want to be using buffer-local values for them, either via mode hooks, or using directory local variables.
What is the problem you're trying to solve?

Password on Emacs Boot Up

I was wondering whether there is a way to ask for a specific password when booting Emacs? I think I can ask for a pre-defined password which I can define in my .emacs file but I dont know how? I'm mainly interested to do this in an x- or graphical environment..
btw, I do know that the .emacs file can be seen and etc..but in my case it's not an issue.
I use epg to keep encrypted data in file. Then it simply loaded as normal emacs lisp file, as in my config. EPG will automatically ask for passphrase, and you can analyze return code of load function to determine, was loading successful or not
If I understand correctly, you are in a situation where multiple people share the same account on a computer -- that is, not only will they run the same emacs binary, they also have the same home directory where Emacs searches for the .emacs file.
It seems like you not only want to prevent others from reading the .emacs file, you actually don't want them to be able to run emacs at all.
Unfortunately for you, Emacs can be started with -q or -Q in which case the .emacs file is not evaluated at all. Thus any "protection" that relies on your .emacs file can easily be circumvented.
How about restricting access to the emacs binary instead? Maybe make it only executable for members of a certain Unix group (which of course is pointless if multiple people share the same account), or something along those lines. But note that this will not prevent them from installing their own local copy of Emacs.

Emacs inside of gedit?

After years of experimentation with editors, the fact is I prefer them as minimal as possible. I never use fancy features and the full-feature IDE's become bloated, heavy, and slow. Of course, when I do something that pretty much requires a specific IDE (like Android dev and Eclipse) I have no problems using it. But most of the time, I use gedit for programming.
However, I like many Emacs commands, and I want to use them occasionally. Is there a way to embed Emacs inside of gedit? For instance, I envision pressing alt-q (or whatever combo) and Emacs mode is enabled, and from then on all my key presses in the current tab do Emacs commands. I press alt-q again, and it turns off. This would allow me the best of both worlds. Anything like this exist, or do I need to write this plugin myself?
No.
I've seen discussion of embedding of Emacs in other applications in the past, and the consensus is that even that's not feasible, let alone what you're suggesting.
You'd be better off identifying what gedit does that makes you want to use it instead of Emacs, and extending Emacs to make it do that, too. (There can't be that much --- gedit doesn't do much.) The extra features can just sit there and wait for you, and you'll find it easier to locate and use them if you're comfortable in Emacs-mode already.
(On top of all the other advantages of Emacs, you gain the ability to use the same editor you use in a windowed environment on the terminal --- a huge advantage.)
Or maybe yes . . .
You can use the External Tools plugin of gedit (look for it in Preferences). Add a new command, bind it to the key you want, and use this script:
#!/bin/sh
FILE_NAME=$GEDIT_CURRENT_DOCUMENT_PATH
emacs $FILE_NAME
If you want it to open in the currently-running Emacs, replace emacs with emacsclient, and add the following to your .emacs:
(server-start)
This is kind of backward. Why don't you just use Emacs and stay away from all the extra bells and whistles? It'd probably be easier to coax emacs to emulate gedit than the other way around.
If gedit (a) can be scripted to launch another application with the current file as an argument, and (b) will notice if the file is modified on disk and offer to reload it, then you would have a workaround.