Burn CD’s and DVD’s from emacs using dired and dvd+rw-tools

I recently explored burning discs from the command line. To make things even more convenient, I can employ emacs dired to help in selecting the files. That is, suppose I have some files in a directory opened in dired. I can mark the files I want to be burnt, and invoke ! (dired-do-shell-command) on those files with the command:

 <pre class="src src-sh">growisofs -dvd-compat -input-charset=ISO-8859-1 -full-iso9660-filenames -Z /dev/sr0 -R -J -pad * &amp;&amp; eject /dev/sr0


I can also invoke & (dired-do-async-shell-command) with the above command without the && eject /dev/sr0 (the * arguments will also be passed to this) to continue using the current emacs instance and view the progress in stdout.

Dissociate C-i, C-m, and C-[ in emacs

Every now and then, I bind functions to keys such as C-m, C-i, and C-[ , but run into issues as these keys are identical to RETURN, TAB, and ESC. See this and the named ascii list for more information. I tried many solutions before but never got them to work. I finally ran across a solution that works, namely Caio’s solution on this post. At the time of this writing, it shows as the last place answer on stacked overflow, so I (and many others) must have missed it. Note that this works only on GUI instances of Emacs and not terminal ones. I will reproduce the solution:

 <pre class="src src-sh">;; Translate the problematic keys to the <span style="color: #00ffff;">function</span> <span style="color: #87cefa;">key</span> Hyper:


(keyboard-translate ?C-i ?H-i) (keyboard-translate ?C-m ?H-m) ;; Rebind then accordantly: (global-set-key [?H-m] ‘delete-backward-char) (global-set-key [?H-i] ‘iswitchb-buffer)

Basically, translate the keys using the hyper, and define the new keybindings using the hyper key. For my use, I did

 <pre class="src src-sh">(global-set-key (kbd <span style="color: #ffa07a;">"C-]"</span>) <span style="color: #ffa07a;">'elscreen-next)</span>


(keyboard-translate ?C-[ ?H-[) (global-set-key (kbd “H-[“) ‘elscreen-previous)

Finally!

Emacs as my default pdf viewer

In the last week, I’ve switched over to using emacs for pdf viewing (reading) via doc-view because I noticed “C-v” and “M-v” did not do what I want in Document Viewer aka Evince ;). At least with OpenOffice, I could remap the navigation keys; not so with Evince. I usually open the pdf files in emacs via dired, but I’m loving it so much that I want it to be the default viewer on my system, i.e., double clicking files in Nautilus. I created the following bash script and set it as the default pdf viewer on my Ubuntu machine.

 <pre class="src src-sh"><span style="color: #ff4500;">#</span><span style="color: #ff4500;">! /bin/</span><span style="color: #00ffff;">bash</span>


Emacs’ universal/prefix argument

I’ve used C-u as a prefix to many key presses in emacs and conkeror before. I never really knew what it did. Recently, I read this that show you how to repeat commands by typing M-#, where # is a number such as 5 or 100, before a command, such as C-n or 0. I’ve also read function definitions in different .el files or emacs’ documentation that speaks of function arguments. I knew that emacs commands correspond to functions, but I never knew how to pass in arguments.

Basically, C-u # and M-# (substitute # with a number) passes numeric arguments to the function called. C-u without # is equivalent to M-4. Read this for a more thorough explanation. This shows how one can “overload” a function using the prefix argument.

using R + ess-remote with screen in emacs

Dear list,

I brought up this issue before but a good solution never arised: being able to use screen on a remote server (so if something goes wrong on my side I can always resume that R session) inside of emacs in order to utilize ESS. The closest thing I found to a good work flow was to use ansi-term or multi-term and copying and pasting code in Emacs (ESS only worked nicely with shell-mode; reason at the end). Some would advise to use screen and open emacs inside of that screen, and voila, you have the luxuries of screen (attaching the session anywhere) and emacs+ESS (keybindings, etc). However, I prefer to use one main emacs session on my laptop/netbook (all my configurations are there), where I can have multiple projects and multiple R jobs opened at once.

I would like to share what I have working (for the time being), with the help of Michael Zeller in case others are interested.

1. Place the following in .emacs:
  <pre class="src src-sh">;; used to send screen keybindings to shell<span style="color: #00ffff;"> in</span> emacs


(define-key shell-mode-map (kbd “C-l”) (lambda (seq) (interactive “k”) (process-send-string nil seq))) (define-key inferior-ess-mode-map (kbd “C-l”) (lambda (seq) (interactive “k”) (process-send-string nil seq)))

1. In xterm (or the likes), ssh to the remote server and start screen. Detach it. (Need to do this first as starting the initial screen in emacs shell-mode becomes very ugly with the printing; resuming the same screen session also becomes messy in xterm)
2. In emacs, M-x shell. Set:
  <pre class="src src-sh">$<span style="color: #eedd82;">TERM</span>=xterm <span style="color: #ff4500;">## </span><span style="color: #ff4500;">give clearing capabilities to shell-mode</span>  1. ssh to remote server. screen -r to resume the screen session. start R. M-x ess-remote. 2. Send R code from R source files like before! 3. To detach or do anything screen related, precede EACH keybinding with C-l. For example, C-a C-d to detach will now be C-l C-a C-l C-d. Yes this is cumbersome, but I don’t imagine screen keybinding to be used much at this stage since we are developing and debugging R code for say a simulation study =]. I would also like to note (for archival reasons) that ess-remote does not work with ansi-term and multi-term because of the inferior-ess-mode command, which stems from comint-mode and inferior-ess-send-input. If you remove this command in ess-remote, you don’t get an error but u can only send one line of code at a time from the R file. Hope this helps someone out there. ControlMaster in OpenSSH – speeding up editing files remotely with emacs + tramp So I was googling around to find out how to change the shell in tramp for emacs, and I ran into this and this. When editing remote files with emacs using tramp, opening and saving files can take a bit of time, due to re-logging in and authenticating. I discovered that you OpenSSH has a feature that allows one to re-use an existing connection to a remote host when opening new connections to that host. This is quite cool. Place the folling in ~/.ssh/config: <pre class="src src-sh">Host *  ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p file management: emacs dired to replace Finder in mac os x (and other OS) I hate Finder in Mac OS X. I mean, it looks nice and all, but it is not customizable. I really liked the KDE window management back when I used Kubuntu because I can select/de-select files with the keyboard, cut/paste/copy files with the keyboard, have shortcuts to different locations, etc. Finder has some keyboard shortcuts, but not at all flexible. You can copy and paste files, but you can’t cut and paste files. Selecting/de-selecting files is not as flexible (eg, skipping a file). I can’t go to the sidebar window where all my bookmarked locations reside using the keyboard. Finder, and in general Mac OS X, is not so flexible. This bugs me a lot. I wanted to get stumpwm working in OS X so that things are more keyboard-oriented. However, it doesnt work with all the native mac apps. The fix is with dired mode in emacs. I spend most of my time in emacs already. With dired, I can even manage files inside emacs (I can do so in the shell, but this makes browsing and executing commands on files a breeze). Use “C-x f” and navigate to a location rather than a file. Learn all the keyboard shortcuts for delete, rename, execute shell command, etc. You can even cut/copy/paste with wuxch-dired-copy-paste. The functions below also allow me to open files the Mac way, with the “open” command. This is cool because files will be opened with the native Mac default application. <pre class="src src-sh">;; http://www.emacswiki.org/emacs/DiredPlus  ;; copy and paste files in dired ;; needed additional files, such as dired+, dired-details+, find-dired+, and find-dired- (require ‘wuxch-dired) (require ‘wuxch-dired-copy-paste) ;;http://stackoverflow.com/questions/1824696/function-to-call-same-shell-command-in-dired ;; (defun dired-do-shell-mac-open-vqn () ;; (interactive) ;; (dired-do-async-shell-command ;; “open” current-prefix-arg ;; (dired-get-marked-files t current-prefix-arg))) (defun dired-do-shell-mac-open-vqn () (interactive) (save-window-excursion (dired-do-async-shell-command “open” current-prefix-arg (dired-get-marked-files t current-prefix-arg)))) (define-key dired-mode-map (kbd “s-o”) ‘dired-do-shell-mac-open-vqn) I can use Apple-o/Windows-o to open files with the default mac program for the marked files.I also use emacs’ bookmark system (“C-x r b” and “C-x r m”) to bookmark locations.Note that all this is not specific to Mac OS X. Dired’s been around forever – I just never picked it up really. Now with my “open” trick and the bookmark system, this should really replace my use of Finder in Mac OS X. Update 11/10/2010 – On Linux I’m back on Linux now. A few updates on launching files with the default application. Add the following to the emacs init file: (defun dired-do-shell-launch-file-default () (interactive) (save-window-excursion (dired-do-async-shell-command "$HOME/Documents/bin/open.sh" current-prefix-arg ;; linux;; multiple files
;; "nohup xdg-open" current-prefix-arg ;; linux can open multiple files, but one at a time
;; "see" current-prefix-arg ;; linux;; can open at most 1 file (being opened)
;; "open" current-prefix-arg ;; mac os x
(dired-get-marked-files t current-prefix-arg))))
(define-key dired-mode-map (kbd "s-o") 'dired-do-shell-launch-file-default)


Need the script open.sh (thank you fledermaus from #emacs):

#! /bin/bash

for file in "$@" do nohup xdg-open "$file" &
done
sleep 1


Now, to unmount devices in emacs:

;; unmount disk in dired
;;http://loopkid.net/articles/2008/06/27/force-unmount-on-mac-os-x
(defun dired-do-shell-unmount-device ()
(interactive)
(save-window-excursion
(dired-do-async-shell-command
"umount" current-prefix-arg ;; linux
;; "diskutil unmount" current-prefix-arg ;; mac os x
(dired-get-marked-files t current-prefix-arg))))
(define-key dired-mode-map (kbd "s-u") 'dired-do-shell-unmount-device)


If an error is returned, make sure the device is not being used anywhere, including opened in nautilus or in some terminal.

The ability to launch files with the default application (look into xdg-open, gnome-open, and see), unmnount devices, and being able to copy/paste files in emacs help makes dired the perfect file manager. I will use this from now on over Nautilus. It’ll compliment using stumpwm.

stumpwm on mac os x

stumpwm is to window managing (tiling?) system what emacs is to text editing and conkeror is to web browsing.

very cool. if i was on a linux laptop/desktop like i used to be, i would definitely use this. i’m even debating on quitting my mac os x for this (with emacs and conkeror). however, i most likely won’t since mac os x is pretty stable and most new stuff will be compatible with it (ease of use, plug and play).

i wanted to get stumpwm working on mac os x (intel based) like this post, but i never got it to work. somehow, i got it to work. my steps:

1. update xquartz like the post said.
2. install sbcl via macports.

UPDATE: actually, i think i used the sbcl for mac via this site.

git clone git://git.savannah.nongnu.org/stumpwm.git

1. followed the README file of stumpwm for sbcl:
  <pre class="src src-sh">\$ sbcl


* (require ‘asdf) * (require ‘asdf-install) * (asdf-install:install ‘clx) * (asdf-install:install ‘cl-ppcre)

this step gave me MANY errors. i kept selecting the option to retry and continue like crazy. i finally gave up.

  <pre class="src src-sh">autoconf <span style="color: #ff4500;">##</span><span style="color: #ff4500;">get if not available. macports?</span>