Page 1 of 23

Emacs tips and tricks

Posted: Sat Nov 02, 2013 12:55 pm
by xaos52
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/

Re: Emacs tips and tricks

Posted: Sat Nov 02, 2013 2:00 pm
by DebianJoe
...but all those wacky keybinds. 8)

Re: Emacs tips and tricks

Posted: Sat Nov 02, 2013 2:37 pm
by xaos52
No perfection without some amount of suffering...

Re: Emacs tips and tricks

Posted: Sat Nov 02, 2013 3:25 pm
by GekkoP
thanks, bookmarked!

Re: Emacs tips and tricks

Posted: Sat Nov 02, 2013 4:15 pm
by GekkoP
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.

Re: Emacs tips and tricks

Posted: Tue Nov 19, 2013 6:34 pm
by xaos52
easily start a version of emacs with alternate configuration
http://www.emacsbites.com/episode/scratch-emacs

Re: Emacs tips and tricks

Posted: Tue Nov 19, 2013 6:37 pm
by GekkoP
^ cool one, especially for testing random stuff I pulled in from the repos.

Re: Emacs tips and tricks

Posted: Thu Nov 21, 2013 7:50 pm
by bones

Re: Emacs tips and tricks

Posted: Thu Nov 21, 2013 7:59 pm
by GekkoP
What!?
RMS doesn't know how to use org-mode? Damn, that hurts.

Re: Emacs tips and tricks

Posted: Fri Nov 22, 2013 3:29 am
by machinebacon
^ 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.

Re: Emacs tips and tricks

Posted: Fri Nov 22, 2013 7:19 pm
by machinebacon
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

Re: Emacs tips and tricks

Posted: Fri Nov 22, 2013 7:21 pm
by GekkoP
yeah, thanks!

Re: Emacs tips and tricks

Posted: Mon Nov 25, 2013 1:55 pm
by xaos52
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

Re: Emacs tips and tricks

Posted: Mon Nov 25, 2013 8:10 pm
by GekkoP
^ nice one!

Re: Emacs tips and tricks

Posted: Tue Nov 26, 2013 5:19 pm
by bones
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.

Re: Emacs tips and tricks

Posted: Sun Mar 16, 2014 12:45 pm
by GekkoP

Re: Emacs tips and tricks

Posted: Mon Mar 24, 2014 11:38 am
by xaos52
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.

Re: Emacs tips and tricks

Posted: Tue May 20, 2014 10:55 am
by GekkoP
Firefox like Emacs? Yes, here it is.

Re: Emacs tips and tricks

Posted: Wed Jun 25, 2014 5:11 pm
by GekkoP
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)

Re: Emacs tips and tricks

Posted: Thu Jun 26, 2014 10:20 am
by GekkoP
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.