Emacs tips and tricks

Forum rules
Share your brain ;)
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 Jun 26, 2014 11:39 am

Thanks for this howto! Recently I have been playing around with different typesetting modes like LaTeX and markdown and other wiki styles. Emacs does this thing very well, and org-mode is basically nothing else than a powerful blog frontend.

Really superb write-up!
..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 Jun 26, 2014 11:43 am

^ thank you, I feel I have to do something because I stole too much from DebianJoe's writings in the past. ;)
I still have to explore (and appreciate) LaTeX and how it works with Emacs, but I'll do it soon.

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 Jun 26, 2014 12:46 pm

^ Works like a dream, I might write it down sometime :)
..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 Jun 26, 2014 12:52 pm

^ Please do!

Another quick one for all you org-mode lovers.

I use org-mode for todo-lists, and I got plenty of them. You should already know that if you put something like "[/]" beside the parent node of a todo list, that little thingy will become something like "[2/10]". Basically, it is telling you how many of your todos are marked as DONE. Very useful.

I don't need to keep all my DONE tasks forever, so every now and then I clean my lists deleting DONE tasks. Org-mode, by default, doesn't update the TODO counter (let's call it like this, for now) when you delete a DONE task.

So, as suggested by the almight What the .emacs.d!?, you can add this to your .emacs and automate the process of updating the TODO counter:

Code: Select all

;; Org-mode: update parent nodes when child is removed
(defun myorg-update-parent-cookie ()
  (when (equal major-mode 'org-mode)
    (save-excursion
      (ignore-errors
        (org-back-to-heading)
        (org-update-parent-todo-statistics)))))

(defadvice org-kill-line (after fix-cookies activate)
  (myorg-update-parent-cookie))

(defadvice kill-whole-line (after fix-cookies activate)
  (myorg-update-parent-cookie))
Now, whenever I kill the DONE task line with a simple C^k, the TODO counter is automagically updated.

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 Jun 26, 2014 1:43 pm

Little keymap fix for emacs -nw:

If - for whatever reasons - you cannot produce a Alt-x to execute extended commands (and you are too lazy to press Esc, or whatever) because it prints out some strange character like a œ or æ, add the following line to your Xresources:

Code: Select all

 *metaSendsEscape:true 
..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 » Wed Jul 02, 2014 12:00 pm

Maybe an obvious one, but for any of you Emacs users tired of GTK3 forced in when you install Emacs via apt-get, here is the solution. Of course you can also go with emacs-nox and work just fine. Stop reading, then, you are already happy. I'm writing this for the ones who use Emacs with X and their favorite WM.

We are going to compile Emacs, because we love compiling don't we? Let's go.

First of all, get the latest version of Emacs. If you want the stable one do:

Code: Select all

wget http://ftpmirror.gnu.org/emacs/emacs-24.3.tar.gz
If you want the latest alpha/test/bleeding/oh-dear-lord-I'm-scared release do:

Code: Select all

wget ftp://alpha.gnu.org/gnu/emacs/pretest/emacs-24.3.92.tar.xz
Extract the archive wherever you want, and cd into the new directory. Having Emacs working with GTK2 instead of GTK3 is just a matter of doing this:

Code: Select all

./configure --with-x-toolkit=gtk2
Really, it is THAT simple.
Now make it and install it:

Code: Select all

make
sudo make install
That's about it. Enjoy your GTK2. :)

Image

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 » Wed Jul 02, 2014 2:43 pm

^ or take the lucid version :) But yes, thanks for the reminder. Actually a shame they don't add a gtk2-forced package to the repos -- for everything else they have shit there :)
..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 » Wed Jul 02, 2014 3:14 pm

^ oh yes, you're right, I forgot about the lucid version. Arch got the gtk2 version, IIRC.

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 Jul 03, 2014 11:16 am

Another one just for you Emacs lovers. This one is about RSS feed. There are many ways to read our feeds. We have newsbeuter and nrss, of course. In Emacs we already have gnus, so why bother with yet another one? Just because.

This one is called elfeed. The website explains the reason behind it, but the important thing is:
elfeed is oriented around entries -- the Atom term for articles -- rather than feeds. It cares less about where entries came from and more about listing relevant entries for reading
Author also says elfeed is availbale on MELPA, but I couldn't install it. So I grabbed the sources and made it work anyway like guys like us always do.

Let's go.

First of all, grab the sources via git:

Code: Select all

git clone https://github.com/skeeto/elfeed
cd into the elfeed directory and compile the little bastard:

Code: Select all

cd elfeed
make
Now it is just a matter of setting elfeed up in our .emacs file. Check your paths and add these lines:

Code: Select all

(add-to-list 'load-path "~/.emacs.d/elfeed")
(require 'elfeed)
(global-set-key (kbd "C-x w") 'elfeed)
(setq elfeed-feeds
      '("http://kmandla.wordpress.com/feed/"
	"http://inconsolation.wordpress.com/feed/"))
You can just add whatever feed you want in there.
Now fire up your Emacs, hit C^x w and elfeed should start. You'll see nothing at first but don't be afraid. Hit G (yep, capital) and you'll get what you are looking for.

Image

User avatar
p120d16y
Haxxor
Posts: 132
Joined: Tue Jan 01, 2013 6:18 pm

Re: Emacs tips and tricks

Unread post by p120d16y » Sun Jul 06, 2014 12:24 am

machinebacon wrote:http://www.finseth.com/craft/

Title The Craft of Text Editing: Emacs for the Modern World
Author(s) Craig A. Finseth
Publisher: Lulu.com; 3rd edition (March 17, 2006)
Paperback 228 pages
eBook Online, HTML, PDF files
Language: English
ISBN-10: 1411682971
ISBN-13: 978-1411682979

A bit late, but thanks a bunch for the book Bacon!

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 » Sun Jul 13, 2014 3:07 am

It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

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 » Thu Jul 24, 2014 4:44 pm

How are experiences with emacs-noX? Personally I've had conflicts, such as finding a prefix for TMUX, and urxvt (e.g. C-M-v scrolls help in emacs, paste in urxvt).
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Emacs tips and tricks

Unread post by bones » Thu Jul 24, 2014 5:39 pm


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 » Fri Jul 25, 2014 2:35 am

@alad, to be honest I prefer the noX version to any with toolkit - but then again I only run emacs in TTY. Actually (well...) Emacs doesn't need to be run in tmux, tell you two reasons: one is, that Emacs itself works with frames and buffers (let me recommend e2wm for this), and secondly because you can 'pretend' to use different (tmux)windows by switching through the TTYs (Alt-cursor). Emacs in tty1, tmux can run on tty2, for example, and you have a radio script running in tty7, and a full-screen clock as 'screen saver' on tty8. This is just a usage example :)

@bones, thank you for the link!
..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 » Tue Aug 19, 2014 5:30 pm

Some nice adds to your config if you are looking for Naked Emacs, as someone smarter than me calls it.

Code: Select all

;; turn off blinking cursor
(blink-cursor-mode 0)

;; turn off mouse interface early in startup to avoid momentary display
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'horizontal-scroll-bar-mode) (horizontal-scroll-bar-mode -1))

;; disable annoying prompts
(fset 'yes-or-no-p 'y-or-n-p)
(setq kill-buffer-query-functions
  (remq 'process-kill-buffer-query-function
         kill-buffer-query-functions))

;; disable splash screen
(setq inhibit-startup-message t
      inhibit-startup-echo-area-message t)

;; disable scratch buffer message
(setq initial-scratch-message nil)

;; tooltips in the echo area
(tooltip-mode -1)
(setq tooltip-use-echo-area t)

;; minor mode to hide the mode line (see http://bzg.fr/emacs-hide-mode-line.html)
(defvar-local hidden-mode-line-mode nil)
(defvar-local hide-mode-line nil)

(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  (force-mode-line-update)
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (redraw-display)
  (when (and (called-interactively-p 'interactive)
             hidden-mode-line-mode)
    (run-with-idle-timer
     0 nil 'message "Hidden Mode Line Mode enabled.")))

;; if you want to hide the mode-line in every buffer by default
(add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

;; custom keybindings activated with C^x t (see http://endlessparentheses.com/the-toggle-map-and-wizardry.html)
(define-prefix-command 'toggle-map)
;; The manual recommends C-c for user keys, but C-x t is
;; always free, whereas C-c t is used by some modes.
(define-key ctl-x-map "t" 'toggle-map)
(define-key toggle-map "v" 'visual-line-mode)
(define-key toggle-map "c" 'column-number-mode)
(define-key toggle-map "l" 'linum-mode)
(define-key toggle-map "h" 'hidden-mode-line-mode)

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 » Wed Aug 20, 2014 4:24 pm

You are writing a text and need to calculate something and paste the result directly where the point is?

M-x quick-calc (or: M-# q)
Enter your calculation in the minibuffer
C-j to send the result to the point (Enter sends it to kill-ring)
..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 » Wed Aug 20, 2014 4:37 pm

^ really handy!

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 » Wed Aug 20, 2014 4:50 pm

I don't know how many of you out there use eshell, but I've been using it lately. Though it will be hard for eshell to get me away from zsh, I appreciate some of the few features I tried. Can't run mutt nor newsbeuter in it, but of course Emacs got its replacements for those, so whatever. Jokes aside, it is nice not to leave Emacs for some basic operations I usually need to do with zsh.

First of all, type M^x eshell to open it.
There are some coreutils commands re-implemented in elisp, but the transition is smooth and you won't notice the difference (maybe). Type ls, for instance.

One thing I found pretty useful is find-file. Using that command you can open a file straight into Emacs from eshell. Since typing find-file everytime is quite boring, enter aliases. Type:

Code: Select all

alias ff find-file $1
Much better. I also did the same for dired:

Code: Select all

alias d dired $1
There is no clear command, though, and when the buffer becomes pretty full of stuff I just need to clear that damn thing. So here we go:

Code: Select all

;; clear shell
;; (see http://www.khngai.com/emacs/eshell.php)
(defun eshell/clear ()
  "clear the eshell buffer."
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))
Ok, this is trivial stuff of course. Have a read here for more: http://www.masteringemacs.org/articles/ ... ng-eshell/

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 » Wed Aug 20, 2014 6:14 pm

You could also just M-x shell :) This brings the real thing :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 » Wed Aug 20, 2014 6:16 pm

^ oh yes, I did know that, but eshell is intriguing (or mind-blowing, it depends). ;)

Post Reply