Emacs tips and tricks
Forum rules
Share your brain ;)
Share your brain ;)
- wuxmedia
- Grasshopper
- Posts: 6454
- Joined: Wed Oct 17, 2012 11:32 am
- Location: Back in Blighty
- Contact:
Re: Emacs tips and tricks
remove bash...
EMACS as an OS - my goodness.
EMACS as an OS - my goodness.
Re: Emacs tips and tricks
^ it's on the grill - now taste it! :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.
Re: Emacs tips and tricks
Since thanks to the grill I got accustomed to git and github, you already knew it wouldn't take me long to find a solution for all that git stuff inside Emacs.
Enter magit.
Magit is a very nice interface for git. It does what I need to do with git pretty well, but it also does something I usually don't need to do so I'll let you discover everything you might want to do with it.
As for my basic usage, here we go.
There are different ways to install magit, I went with MELPA:
In Emacs now all you need is:
Now, if the buffer you're in is under git control you will see the beautiful magit window. Otherwise, you will get a prompt that let you look for you git repository.
This is git, so through some keybindings you can do what you usually do in the command line. For instance, let's say I edited the file TEST in my repo. First thing I need to do is add it before commit. Move the point over the file and type 's'. Now TEST is in the staging area, ready for commit. You can type 'u' to unstage the file, if you did something wrong and want to fix it. To quickly move all your edited files in the staging area just type 'S'. Typing 'U' will unstage everything.
Once in staging area, type 'c' to write a message about the commit you are ready to do. Then commit your file (or files) with 'C-c C-c'.
Now the only thing left is pushing your commit. Just type 'P P' and you're done.
If you need to pull something, typing 'F F' is just the same as 'git pull'.
If for some reason magit lacks something you need to do with git (or you don't know the keybinding for that), just hit ':'. Magit will prompt you for a git command just as if you were in the command line. Handy.
These are just the basics, of course. Check the magit documentation for more.
Enter magit.
Magit is a very nice interface for git. It does what I need to do with git pretty well, but it also does something I usually don't need to do so I'll let you discover everything you might want to do with it.
As for my basic usage, here we go.
There are different ways to install magit, I went with MELPA:
Code: Select all
M-x package-install RET magit RET
Code: Select all
M-x magit-status
This is git, so through some keybindings you can do what you usually do in the command line. For instance, let's say I edited the file TEST in my repo. First thing I need to do is add it before commit. Move the point over the file and type 's'. Now TEST is in the staging area, ready for commit. You can type 'u' to unstage the file, if you did something wrong and want to fix it. To quickly move all your edited files in the staging area just type 'S'. Typing 'U' will unstage everything.
Once in staging area, type 'c' to write a message about the commit you are ready to do. Then commit your file (or files) with 'C-c C-c'.
Now the only thing left is pushing your commit. Just type 'P P' and you're done.
If you need to pull something, typing 'F F' is just the same as 'git pull'.
If for some reason magit lacks something you need to do with git (or you don't know the keybinding for that), just hit ':'. Magit will prompt you for a git command just as if you were in the command line. Handy.
These are just the basics, of course. Check the magit documentation for more.
Re: Emacs tips and tricks
Especially useful for beginners (such as myself): https://github.com/bbatsov/guru-mode
Re: Emacs tips and tricks
https://github.com/relevance/org-html-slideshow
This one is pretty cool (at least for what I need here): org files to HTML presentation slideshows. Just follow the instructions and enjoy your slides.
This one is pretty cool (at least for what I need here): org files to HTML presentation slideshows. Just follow the instructions and enjoy your slides.
Re: Emacs tips and tricks
About keybinds, I'm surprised ergoemacs was not mentioned yet. It has a "notepad-ish" interface*, as well as some added features (such as improved language support, a Redo feature and a dmenu-like minibuffer). Not all is well; it has some bugs and REQUIRES the use of emacs-daemon (unless you want to wait 10s for every new emacs window).GekkoP wrote:Especially useful for beginners (such as myself): https://github.com/bbatsov/guru-mode
* You should decide for yourself how this suits your needs - in my case, the regular emacs keybinds strained my hands too much, as if doing a typing course.
PS: @mb: Thanks for the noX tips. I now tend to use the noX version more, though inside X, the GTK version's clipboard integration is handy.
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer
Re: Emacs tips and tricks
The more I use Emacs, the more my .emacs gets new stuff in it. Tired of scrolling around, I tried a solution to make the maintenance easier.
One note: I took bits from the EmacsWiki, so refer to that if you need more. Also, this is a solution that works for me. There are other ways to manage your Emacs configuration. Some use starter kits, some use org init files, some just use vim and don't give a damn about all this stuff.
Do whatever you want, as usual.
Let's go.
First of all, I created a 'config' directory in my .emacs.d. It looks like this:
Basically, different files for different needs. The names should be pretty clear of what the contents are. Now I only need to load them when Emacs starts.
I have a load-directory.el in my .emacs.d to accomplish that:
So now my .emacs just looks like this:
I can easily add more files to ~/.emacs.d/config or create sub-directories if needed.
One note: I took bits from the EmacsWiki, so refer to that if you need more. Also, this is a solution that works for me. There are other ways to manage your Emacs configuration. Some use starter kits, some use org init files, some just use vim and don't give a damn about all this stuff.
Do whatever you want, as usual.
Let's go.
First of all, I created a 'config' directory in my .emacs.d. It looks like this:
Code: Select all
~/.emacs.d/config ls
01-packages.el 02-style.el 03-modes.el 04-keybindings.el
I have a load-directory.el in my .emacs.d to accomplish that:
Code: Select all
(defun load-directory (directory)
"Load recursively all '.el' files in DIRECTORY."
(dolist (element (directory-files-and-attributes directory nil nil nil))
(let* ((path (car element))
(fullpath (concat directory "/" path))
(isdir (car (cdr element)))
(ignore-dir (or (string= path ".") (string= path ".."))))
(cond
((and (eq isdir t) (not ignore-dir))
(load-directory fullpath))
((and (eq isdir nil) (string= (substring path -3) ".el"))
(load (file-name-sans-extension fullpath)))))))
Code: Select all
;; Emacs init file
;;
;; This file simply loads the different configuration files
;; I have in ~/.emacs.d/config.
;;
;; This setup makes the maintenance easier.
;;; Load all ".el" files under ~/.emacs.d/config directory.
(load "~/.emacs.d/load-directory")
(load-directory "~/.emacs.d/config")
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Emacs tips and tricks
That's a much better idea, yes, thanks. I noticed the same when I scrolled through Sacha Chua's .emacs configuration. I didn't extend mine a lot (I use org-mode mostly, a bit of Gnus and only need the package-list packages, y/n for yes/no, toolbar/... off), but it does make sense to modulize it - that's what .emacs.d/ is for :)
..gnutella..
Re: Emacs tips and tricks
Just gonna drop this off, but you could actually use custom key binding defined in a loaded .el to load only the specific configurations and routines for a single session, thus...only load what you needed, and on-demand.
Re: Emacs tips and tricks
^ is it similar to use autoload? I'm asking because I haven't tried any of these solutions (yet).
Re: Emacs tips and tricks
Yes, it would be like a hot-keyed autoload. Only real difference being that you would be defining the situations that you wanted your lisp routine to consider before evaluating. Essentially, you can create more horrible emacs key chain combos that would evaluate a subprocess (if you wanted to write it) before the final evaluation.
For example: C^M^S^foobar now runs a short .el that you wrote to check if you're able to ping google with a non-nil result, and IF successful THEN executes emacs-w3m...ELSE, it gives you a message in the mini-buffer that says "Not connected to the internet, probably your fault!"
Obviously, this isn't specific to any one thing, but rather just more possible ways to deal with writing short lisp routines to cover routine tasks efficiently. It's much the same as we'd do with shell-scripting, but integrated into the REPL that emacs is already utilizing. The sky is the limit to the uses.
For example: C^M^S^foobar now runs a short .el that you wrote to check if you're able to ping google with a non-nil result, and IF successful THEN executes emacs-w3m...ELSE, it gives you a message in the mini-buffer that says "Not connected to the internet, probably your fault!"
Obviously, this isn't specific to any one thing, but rather just more possible ways to deal with writing short lisp routines to cover routine tasks efficiently. It's much the same as we'd do with shell-scripting, but integrated into the REPL that emacs is already utilizing. The sky is the limit to the uses.
Re: Emacs tips and tricks
^ thanks for the explanation. That 'ping' thing might be useful.
Re: Emacs tips and tricks
Another one for you, lovely Emacs users: https://github.com/browse-kill-ring/browse-kill-ring
If you 'kill' a lot in Emacs, you might want an easy way to browse all that stuff and quickly get what you killed half an hour ago.
If you 'kill' a lot in Emacs, you might want an easy way to browse all that stuff and quickly get what you killed half an hour ago.
Re: Emacs tips and tricks
Scared of RSI?
Those wacky keybindings just make your hands turning against yourself slapping your face violently?
Try this one: https://github.com/bbatsov/god-mode
I don't have it, but my hands already gave up on me.
Those wacky keybindings just make your hands turning against yourself slapping your face violently?
Try this one: https://github.com/bbatsov/god-mode
I don't have it, but my hands already gave up on me.
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Emacs tips and tricks
TBH I don't know where the RSI-fear @emacs comes from. Well, depends on what people do - and it definitely depends on the keyboard and the location of the Ctrl key. But Escape or Caps Lock is not really that much better, IMO. Of course everybody can do what he wants. ;)
..gnutella..
Re: Emacs tips and tricks
^ I agree. My only problem is the right-hand pinky. It has nothing to do with Emacs, but I type quite a lot during the day and the Enter key is the main issue.
(Birthday is coming, so maybe I can get someone to buy me an ergonomic keyboard.)
(Birthday is coming, so maybe I can get someone to buy me an ergonomic keyboard.)
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Emacs tips and tricks
Yeah, here too, Enter is the problem, especially the laptop-Enter which is like a shorter Shift.
Dog-mode switches Enter to Space, Space to Ctrl, Ctrl to Caps Lock and Escape to .... errr :D
Dog-mode switches Enter to Space, Space to Ctrl, Ctrl to Caps Lock and Escape to .... errr :D
..gnutella..
Re: Emacs tips and tricks
I know I might be the only one here using Emacs in X, buy anyways...
Compiling Emacs with GTK2/GTK3 toolkit and running it as daemon could get you into this:
- emacsclient -c in workspace 2;
- C-x C-c on that client;
- mutt (workspace 1) calls emacsclient -t to let me compose my e-mail;
- emacs server is down and have to restart it.
Very annoying.
Since running it as daemon is really useful, I had to compile it using Lucid toolkit like that note says. I have already removed everything GUI related, so it makes no difference. Pressing F10 pops up the menu and my-oh-my that is ugly, but whatever, no crashes anymore.
Compiling Emacs with GTK2/GTK3 toolkit and running it as daemon could get you into this:
It happened to me in the following situation:** When Emacs is compiled with Gtk+, closing a display kills Emacs.
There is a long-standing bug in GTK that prevents it from recovering
from disconnects: http://bugzilla.gnome.org/show_bug.cgi?id=85715.
Thus, for instance, when Emacs is run as a server on a text terminal,
and an X frame is created, and the X server for that frame crashes or
exits unexpectedly, Emacs must exit to prevent a GTK error that would
result in an endless loop.
If you need Emacs to be able to recover from closing displays, compile
it with the Lucid toolkit instead of GTK.
- emacsclient -c in workspace 2;
- C-x C-c on that client;
- mutt (workspace 1) calls emacsclient -t to let me compose my e-mail;
- emacs server is down and have to restart it.
Very annoying.
Since running it as daemon is really useful, I had to compile it using Lucid toolkit like that note says. I have already removed everything GUI related, so it makes no difference. Pressing F10 pops up the menu and my-oh-my that is ugly, but whatever, no crashes anymore.
-
- Baconator
- Posts: 10253
- Joined: Thu Sep 16, 2010 11:03 am
- Location: Pfälzerwald
- Contact:
Re: Emacs tips and tricks
..gnutella..
Re: Emacs tips and tricks
^ oh nice, thanks.