Emacs tips and tricks

Forum rules
Share your brain ;)
User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Emacs tips and tricks

Unread post by wuxmedia » Wed Aug 20, 2014 6:48 pm

remove bash...
EMACS as an OS - my goodness.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Emacs tips and tricks

Unread post by rhowaldt » Wed Aug 20, 2014 10:44 pm

^ 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.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Aug 21, 2014 9:23 am

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:

Code: Select all

M-x package-install RET magit RET
In Emacs now all you need is:

Code: Select all

M-x magit-status
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.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Aug 21, 2014 6:12 pm

Especially useful for beginners (such as myself): https://github.com/bbatsov/guru-mode

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Tue Aug 26, 2014 11:57 am

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.

User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: Emacs tips and tricks

Unread post by Alad » Wed Aug 27, 2014 6:07 am

GekkoP wrote:Especially useful for beginners (such as myself): https://github.com/bbatsov/guru-mode
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).

* 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

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Aug 30, 2014 8:53 am

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:

Code: Select all

~/.emacs.d/config ls
01-packages.el    02-style.el    03-modes.el    04-keybindings.el
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:

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)))))))
So now my .emacs just looks like this:

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")
I can easily add more files to ~/.emacs.d/config or create sub-directories if needed.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Sat Aug 30, 2014 12:46 pm

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..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Sat Aug 30, 2014 1:52 pm

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.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Aug 30, 2014 2:27 pm

^ is it similar to use autoload? I'm asking because I haven't tried any of these solutions (yet).

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Sat Aug 30, 2014 2:56 pm

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.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Aug 30, 2014 3:30 pm

^ thanks for the explanation. That 'ping' thing might be useful.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Tue Sep 02, 2014 3:23 pm

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.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Sep 04, 2014 2:01 pm

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.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Thu Sep 04, 2014 2:13 pm

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..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Sep 04, 2014 2:28 pm

^ 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.)

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Thu Sep 04, 2014 2:33 pm

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
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Sep 04, 2014 4:23 pm

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:
** 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.
It happened to me in the following situation:
- 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.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Thu Sep 04, 2014 6:03 pm

..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Sep 04, 2014 6:18 pm

^ oh nice, thanks.

Post Reply