(update: a valid answer can include "there is no neat/automated way of doing this) I've been keeping myself busy with other things but if I know there is no neat way of doing what is requested below then I'll just get started on finding some manual way as much as possible.
I have been looking online for a way to ensure all my emac buffers use the same keybindings. However I use exwm & certain applications such as libreoffice have their own keybindings which take precedence over emacs keybindings. Is there some code I can use to make all emacs default keybindings take precedence over any other application?
A specific example is this situation:
I want to be able to use the default bindings to change which buffer I am using position wise. I do this using (windmove-default-keybindings) however when I switch to an application like libreoffice writer, that application makes it so S-arrowkey doesn't move my active buffer anymore (libreoffice takes over that keybinding). I wish for windmove to still control what S-arrow key does.
In general this means I want emacs to be the only application in control of any keybinding. Is the only way to do this is to set each keybinding as global manually? and will a global keybinding take precedence over applications like libreoffice?
Related
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.)
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.
I am not particularly satisfied how the viper mode works in Emacs. I am trying to write my own viper mode. I do not have any good programming experience in Elisp except for the number of customizations I have done using the .emacs file.
I would like to know if I can change the key-bindings in Emacs temporarily and return them back to their original state as and when needed.
Well if I understand your question correctly one easy way to do this would be to create your own minor mode (in addition to your own specific mode I'd say), made only of your temporary key-bindings.
You give a name to that mode and then toggling all your temporary key-bindings on or off becomes as simple as calling your command:
M-x salsabear-minor-mode
You probably want to read scottfrazer's 45+ upvotes answer here on SO:
Globally override key binding in Emacs
where he explains how to create your own minor-mode containing your key-bindings.
Given that you explicitly only mention viper, it's probably worth asking whether you're aware of the other vi/vim-based libraries which exist? See the list under:
http://www.emacswiki.org/emacs/CategoryEmulation
I would suspect that re-inventing this particular wheel is probably not worthwhile.
I believe that Evil is the most active project, but if it doesn't work the way you want, your efforts might be better-spent enhancing that (if practical)?
I need to implement some new functions on an editor. I picked Emacs - although my main programming knowledge is in Java and C - and I want to add some functions and edit some existing functions of Emacs Editor. I looked at the source code of it and I'm a bit lost. I was wondering whether anyone can give me some advice about where to start and whether there are any tutorials that can help?
P.S. One specific question would be how one can start to write a new mode with all new features and behaviour? or how I can disable some basic functions like copy/paste?
Cheers
An Introduction to Programming in Emacs Lisp http://www.gnu.org/software/emacs/emacs-lisp-intro/ or type in emacs:
M-: (info "(eintr)Top") RET
Emacs Lisp Manual http://www.gnu.org/software/emacs/manual/elisp.html or type in emacs:
M-: (info "(elisp)Top") RET
There are some tutorials out there specifically geared towards writing a major mode.
emacs extension guide [pdf]
how to write a major mode...
Other than that, writing modes in Emacs is just writing Lisp functions.
One thing I will note is that what you're proposing to do here may be pointless; if you implement a permission system as a major mode, a user can simply switch modes to turn it off. That's fine if the point of this permission system is to avoid clobbering edits (in which case I assume your users will cooperate with your aims). If you're expecting your users to be adversarial, then Emacs is the wrong tool for this.
Here is the manual section on defining major and minor modes:
C-hig (elisp) Modes RET
It is often beneficial to derive a new mode from an existing one which provides similar basic functionality to what you need.
If there's nothing which matches closely enough, examining the source code for modes which provide some of the same behaviour would be the next best thing.
I note that 'deriving' a mode from nil seems to be the common way of creating a completely new major mode. That way you still get all the benefits of the define-derived-mode macro.
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.