Emacs tips and tricks

Forum rules
Share your brain ;)
User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Emacs tips and tricks

Unread post by xaos52 » Sat Nov 02, 2013 12:55 pm

Navigating and editing in emacs using the keyboard.
Re-read it until you master it...
Make a cheat-sheet of the mentioned commands.
http://www.masteringemacs.org/articles/ ... -movement/
Connected. Take this REPL, brother, and may it serve you well.

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 Nov 02, 2013 2:00 pm

...but all those wacky keybinds. 8)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Emacs tips and tricks

Unread post by xaos52 » Sat Nov 02, 2013 2:37 pm

No perfection without some amount of suffering...
Connected. Take this REPL, brother, and may it serve you well.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Nov 02, 2013 3:25 pm

thanks, bookmarked!

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Nov 02, 2013 4:15 pm

One of my favorite tricks is the column selection. It is really helpful when I'm editing a file and I want to copy/cut a rectangular portion of the text.
Here's what I do:

M-x cua-mode
Place point at the beginning of the text I want to select
C-Enter
Select the text using C-f and C-n.
C-k to cut (or M-w to copy)
C-y to paste somewhere else in the file

cua-mode also enables the """standard""" copy/cut/paste using C-c/C-x/C-v, but I stick with Emacs keys. You can also enable just cua-selection-mode, if you don't care about C-c/C-x/C-v.

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Emacs tips and tricks

Unread post by xaos52 » Tue Nov 19, 2013 6:34 pm

easily start a version of emacs with alternate configuration
http://www.emacsbites.com/episode/scratch-emacs
Connected. Take this REPL, brother, and may it serve you well.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Tue Nov 19, 2013 6:37 pm

^ cool one, especially for testing random stuff I pulled in from the repos.

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 Nov 21, 2013 7:50 pm


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

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Nov 21, 2013 7:59 pm

What!?
RMS doesn't know how to use org-mode? Damn, that hurts.

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 Nov 22, 2013 3:29 am

^ I suppose he doesn't even know how to use a web browser, since he sends snapshots of websites via a crawler to his email box.
..gnutella..

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 Nov 22, 2013 7:19 pm

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

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

Re: Emacs tips and tricks

Unread post by GekkoP » Fri Nov 22, 2013 7:21 pm

yeah, thanks!

User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Emacs tips and tricks

Unread post by xaos52 » Mon Nov 25, 2013 1:55 pm

I prefer directories grouped at the beginning, in an xterm as well as in emacs.
For the xterm, update your ~/.bashrc to include the alias

Code: Select all

     
alias ls='ls --color=auto --group-directories-first'
For emacs, custumize group 'dired': Alt-x customize-group, enter dired and edit the entry 'Dired Listing Switches' as in the scrot.
Then click 'Apply and Save' if you want it to stick.

Image
Connected. Take this REPL, brother, and may it serve you well.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Mon Nov 25, 2013 8:10 pm

^ nice one!

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 » Tue Nov 26, 2013 5:19 pm

So, you use an OS for over a decade, and it turns out you don't know shit about it. *facepalm* It's been there all along. Duh.

Image

EDIT: Jeezus, nano and vim are there, too.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sun Mar 16, 2014 12:45 pm


User avatar
xaos52
The Good Doctor
Posts: 190
Joined: Thu Aug 15, 2013 11:59 am
Location: Eernegem, Belgium

Re: Emacs tips and tricks

Unread post by xaos52 » Mon Mar 24, 2014 11:38 am

Package managers for emacs:

- the native `package.el'
- el-get: if you prefer the latest and greatest from git repo's
- cask: built on `package.el'
now at version 0.6. Allows you to build your own packages.

Pick the one you prefer, depending also on how adventurous you are.
Connected. Take this REPL, brother, and may it serve you well.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Tue May 20, 2014 10:55 am

Firefox like Emacs? Yes, here it is.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Wed Jun 25, 2014 5:11 pm

Ok, finally my days of elisp are paying off. I also know DebianJoe would be proud of me because of this one.
I don't know if any of you have to deal with .po files. Dealing with translations (and translators) I have to deal with those files. I don't want to use poedit for that because of gtk3, so Emacs to the rescue.

Emacs has a mode for .po files: po-mode. If you have followed DebianJoe's tips and tricks about el-get in Emacs (and if not, shame on you), po-mode is just a matter of el-get-install.

By default, when you finish your .po file editing and validate it via po-mode hitting 'V', no .mo file is generated. Po-mode redirects msgfmt to /dev/null and that's not what I need. Basically I need the .mo file, because of some wordpress themes and plugins I usually work with.

So I opened ~/.emacs.d/el-get/po-mode/po-mode.el and changed this function:

Code: Select all

(defun po-validate ()
  "Use 'msgfmt' for validating the current PO file contents."
  (interactive)
  ; The 'compile' subsystem is autoloaded through a call to (compile ...).
  ; We need to initialize it outside of any binding. Without this statement,
  ; all defcustoms and defvars of compile.el would be undone when the let*
  ; terminates.
  (require 'compile)
  (let* ((dev-null
          (cond ((boundp 'null-device) null-device) ; since Emacs 20.3
                ((memq system-type '(windows-nt windows-95)) "NUL")
                (t "/dev/null")))
         (compilation-buffer-name-function
          (function (lambda (mode-name)
                      (concat "*" mode-name " validation*"))))
         (compile-command (concat po-msgfmt-program
                                  " --statistics -c -v -o " dev-null " "
                                  (shell-quote-argument buffer-file-name))))
    (po-msgfmt-version-check)
    (compile compile-command)))
To this:

Code: Select all

(defun po-validate ()
  "Use 'msgfmt' for validating the current PO file contents."
  (interactive)
  ; The 'compile' subsystem is autoloaded through a call to (compile ...).
  ; We need to initialize it outside of any binding. Without this statement,
  ; all defcustoms and defvars of compile.el would be undone when the let*
  ; terminates.
  (require 'compile)
  (let* ((compilation-buffer-name-function
          (function (lambda (mode-name)
                      (concat "*" mode-name " validation*"))))
         (compile-command (concat po-msgfmt-program
                                  " --statistics -c -v -o "
                                  (substring buffer-file-name 0 -2) "mo "
                                  (shell-quote-argument buffer-file-name))))
    (po-msgfmt-version-check)
    (compile compile-command)))
Then, in Emacs you just need to do a M^x byte-compile-file. That's it. Restart Emacs, edit your .po files and enjoy the .mo files created for you in your working directory.

(there surely is a better solution to the problem, my elisp is not that good, but it works for me and no need to use poedit anymore)

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

Re: Emacs tips and tricks

Unread post by GekkoP » Thu Jun 26, 2014 10:20 am

So, org-mode.
A neat trick with this one is org2blog. What is org2blog? It is just an easy way to write and publish your blog posts without leaving your favorite text editor. I only tested it with my website, which is working on Wordpress, so I cannot guarantee it will work with other platforms. Also, this is what I did and it may not be the only and best way to setup org2blog.

Let's go.
First of all, my Emacs 24.3.1 had Org 7.x instead of 8.x. We need 8.x version, otherwise errors like "Cannot open load file ox-html" will scare us away. Check what version of Org you have with M^x org-version. If you don't have 8.x, just get it with git like this:

Code: Select all

git clone git://orgmode.org/org-mode.git
cd org-mode
make
Now we can safely add this to our .emacs (double check your paths, of course):

Code: Select all

;; Org-mode
(add-to-list 'load-path (expand-file-name "~/org-mode/lisp"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(require 'org)
Do a M^x org-version just to check that everything worked as you were expecting.
We need bzr to install org2mode, so:

Code: Select all

sudo apt-get install bzr
Now we need to install org2blog and some other packages it needs to properly work. In Emacs, using el-get or package-install or whatever you use to grab packages, install the followings:

Code: Select all

M^x el-get-install RET xml-rpc
M^x el-get-install RET metaweblog
M^x el-get-install RET org2blog
M^x el-get-install RET htmlize
Then we can add this to our lovely .emacs (double check your paths, of course):

Code: Select all

;; org2blog setup
(add-to-list 'load-path "~/.emacs.d/el-get/metaweblog")
(add-to-list 'load-path "~/.emacs.d/el-get/xml-rpc-el")
(add-to-list 'load-path "~/.emacs.d/el-get/org2blog")
(add-to-list 'load-path "~/.emacs.d/el-get/htmlize")
(require 'org2blog-autoloads)

(setq org2blog/wp-blog-alist
           '(("my-blog"

              :url "http://our.website.com/xmlrpc.php"
              :username "our_username")))

(setq org2blog/wp-use-sourcecode-shortcode 't)
(setq org2blog/wp-sourcecode-default-params nil)
We're almost there.
In Emacs now you can do M^x org2blog/wp-login and you will be prompted for your password. Once logged in, do a M^x org2blog/wp-new-entry and start writing your cool poetry.
Org2blog will let you define, among other things, categories, tags, description, title and of course the text you want to be published.
Once you are done with the writing, it is time for the publishing. Just hit M^x org2blog/wp-post-buffer and you will find your post in draft on your website.

Post Reply