Editing in Emacs

This post is a summary of built-in shortcuts. I keep learning bits and pieces so I thought I should list them all and compare them.

Movement

Key Action
C-n down line
C-p up line
C-f forward char
M-f forward word
C-M-f forward by expression
M-b back word
C-b back char
C-M-b backward by expression
C-a start of line
M-a start of sentence
C-e end of line
M-e end of sentence
M-m first non-blank on line
C-v scroll down a page
M-v scroll up a page
C-M-v scroll the other window down
C-M-S-v scroll the other window up
M-< start of buffer
M-> end of buffer
C-x h select entire buffer
C-M-d down in list
C-M-u up in list
M-g g goto line
M-} foward “element”
M-{ back “element”

Killing

Key Action
M-d delete word forward
M-BACKSPACE delete work backward
C-k kill from point ’til end of line

Yanking

Key Action
C-y yank last string
M-y iterate through yanked strings

Searching (isearch)

Key Action
C-s search forward
.. C-w add word after cursor (repeat C-w for more)
.. C-h C-h show isearch help
.. M-e edit search term
C-M-s regexp search forward
C-r search backward
C-M-r regexp search backward
M-s o list regexp occurrences in new window
M-s w fuzzy find
M-g M-n next entry in error/grep/occur list
M-g M-p prev entry in error/grep/occur list

Registers

Key Action
C-x r SPC store point in register
C-x r j jump to the point in the register

Bookmarks

Key Action
C-x r m save a named bookmark
C-x r b jump to a named bookmark
C-x r l save all bookmarks

Posted in Productivity | Tagged , | Leave a comment

MPlayer compilation in Cygwin

We bought some Di$ney DVDs for our kids in Japan. They like the stories but there are a couple of problems.

  1. We didn’t buy any DVD player after moving and I can’t find a DLNA server that will play direct from disk.
  2. The very considerate corporate drones in Di$ney have made sure that we have to sit through ridiculously long ads unless you select the “enhanced fast start” option on startup. (For “enhanced”, read “the normal format before greed took precedence over user convenience”)

So I’d like to copy our DVDs to my laptop and stream it to the TV via DLNA without ads when the kids want it. (I still find it incredible that I have to go to so much trouble to make something legal, usable?!)

I thought I’d try MPlayer because it’s popular, seems to have a lot of codecs available and it’s something different. Besides, I’m curious to see how much trouble it is to build something like this from cygwin.

Setup

  1. Install Cygwin
  2. Install alias for GNU Emacs in Windows
  3. Download the source and codecs for MPlayer
  4. tar --xvf in the cygwin terminal to extract the files

Configure

Just running ./configure produces some error messages. I’m missing the codecs (I’ve put them in a separate folder) and there are some core packages missing. In my case yasm is missing.

I selected yasm by running the cygwin setup again. Now the configure is running through but I suspect there are more libraries that I could find in cygwin.

I found that I need the --enable-gui option to get a GUI. I also need to use another command line arg: --codecsdir=DIR.

Compilation

Everything seems to work OK but there are a load of warnings. My first compilation doesn’t seem to see my DVD properly, so I recompile with the GUI option. I’ve downloaded the “Blue” skin so this has to go into the .mplayer/skins/Blue directory. Then I added skin=Blue to the .mplayer/config file.

‘Make’ succeeds and I get the correct output but without any gui?! What’s up with that? –> It seems that the gui must be run from the windows system. In the case of cygwin, that appears to be X11. Not to worry; the command line arguments seem relatively simple.

./mplayer DVD:\\1

The empire strikes back

Ah, but the soulless corporate giant has prevailed. Only the extras on the DVD are playable. The title for the film is unplayable. Mplayer borks almost immediately.

Time to download the latest version of VLC I think.

Conclusion

The integration of Win emacs and cygwin seems to work quite well, although I will have to change the shell to cygwin if I use it long term. The configuration was painless and the error messages obvious, even for someone who’s unfamiliar with the encoding libraries. All in all I was quite impressed.. despite the victory of corporate psychosis

Posted in Programming | Tagged , , | Leave a comment

Rat-race

“… and don’t forget that the output may only be correct if you cross reference the configurations”, Elton said in a tight voice, yet again interrupting Hilda mid-sentence. Johannes chimed in with a further comment. Hilda just grimaced slightly while looking at the podium. There were around 30 people in the room around me but I suspected that I wasn’t the only one who saw an undercurrent in the relationship between the presenters.

The presentation was intended as training for SW developers provided by our group. The three presenters, Johannes, Hilda and Elton, have been recently nominated as experts on the same topic. Johannes is the most experienced and has been involved in the original development. He’s normally very helpful but likes to work in an unstructured way. Hilda is clever and has picked up a remarkable amount of detail in a year or so of development. Unfortunately, she’s also not very pro-active. She demurs to Johannes on most all topics but probably more out of practicality than respect, and I can sense a lot of frustration building up underneath.

Elton is the upstart. He’s from a different group, younger than either of the other two. He’s also a foreigner but with pretty good language ability. He upset Johannes straight away by insisting on giving some structure to the overall area and trying to decide on priorities. He can also be prickly and his priorities are sometimes confused. Giving demonstrations he also seems to fall into the trap of presuming the explanation is clear because he understands it instead of thinking about how a beginner would understand it. All this adds up to a slight imbalance in his effectiveness but he actually shows more potential than Johannes in the long run if he gains more experience.

The end result is that the three engineers are competing for the same topic and against each other.

Today is the culmination of delicate negotiation. They agreed to share presentation of the latest training. Johannes mentioned to me that he has no time for Elton, Hilda told me that Johannes rewrote the material on the Sunday night before the training. Elton forced the usage of a particular tool in the presentation content. In total, it sounded more like the Mexican stand-off in reservoir dogs than a reasoned negotiation between professionals.

Part of this is the politics of the role. For engineers, who want to advance, there is a path to the dark side via management, or the possibility of promotion via an “Expert” rating. The organisation has been changed around a few times in the last few months so this particular death-match was not intended.

The training course started to run aground when Johannes started to correct the other two presenters mid-sentence. Not to be out-done, Elton returned the favour.

The end-result is Johannes is full of testosterone and quite cranky. Problem: I have to work with him on my current task and he’s like a demon….

Posted in Personal | Tagged | Leave a comment

Editing your file names

Reblogged from minor emacs wizardry:

Click to visit the original post

In my experience, dired is one of the most underused modes of Emacs. Just C-xC-f to any directory in your hard disk and you'll be presented with a list of its files and directories. One can browse this list, and execute all kinds of commands and transformations on them. If you've never done that before, just give it a try, and look at the menubar for a list of nifty things you can do inside dired.

Read more… 203 more words

The nice thing about Emacs is that every time I go looking I find some more built-in functionality that saves even more time.....
Posted in Programming | Tagged , | Leave a comment

Effective Firefox Shortcuts

Jumping from one SW application to another can be frustrating if I’m in a hurry. The main problem is having to switch between keyboard and mouse. There are most definitely use-cases for mouse usage but for quick, effective actions, the keyboard and command line always prove more effective for me. I’ve noticed that a lot of the bottleneck comes from quick searches on our work intra-net or online-searches for additional information.

My favourite solution

  1. Install the DuckDuckGo search engine in firefox (right click the search and click “Manage”)
  2. go to the intra-net/internet pages that contain the searches you use most often
  3. For each of these pages, select the search field for the page, right-click the search field and select the “add a keyword” option from the context menu. This will add a firefox “smart keyword”.

Smart Keywords

I use the smallest memorable keyword possible e.g.

  • google search = “g”,
  • google image search = “gimg”
  • intra-net people search = “ppl”
  • intra-net wiki search = “iw”
  • stack exchange search = “stack”

A better search engine

DuckDuckGo presents a number of advantages for me.

  • it doesn’t monetise my personal information
  • it allows selection and movement through search results via keyboard shortcuts
  • it allows special keywords to restrict the search
  • there seems to be less rubbish included in the searches

Apart from the nifty java-script keyboard shortcuts, the main reason I love DuckDuckGo is because they provide the same sort of quality of results and clear interface that google search used to provide before it got turned into a bloated, GUI Frankenstein of instant searches and graphical previews where useful options are hidden behind menu picks (“cached pages” anyone? I guess that’s what happens when you poach Microsoft bloatware architects)

A decade and a half ago, I changed from AltaVista to google for similar reasons. I have a feeling of deja-vu, deja-vu, deja-vu…..

Use-Case

You’re working on a SW design or a piece of code. You have to look up:

  1. a contact name on the intra-net e.g. John Smith
    • Solution: <Alt-TAB> to Firefox then <Ctrl+t><Ctrl+l>ppl John Smith<Enter>

    This will open a new tab, switch to the location bar and search for “John Smith”

  2. related technical information on “Ethernet security”
    • Solution: <Ctrl+k>ethernet security<Enter> then j or k to move through the results, then <Ctrl+Enter> to open a page
  3. search for a sample code fragment for opening a socket on Stack Exchange
    • Solution: <Alt-TAB> to Firefox then <Ctrl+t><Ctrl+l>stack open socket<Enter>

What now?…

“So you’ve open one of the resulting pages, then it’s back to the mouse so what have time is really saved?”, I hear you ask. Well, actually firefox will allow you to navigate pages with the keyboard.

Key Action
<SPACE> Scroll down one page
<Shift+SPACE> Scroll up one page
<Ctrl+f> Search text
<’> Search link text
<TAB> Move to next link
<Shift+TAB> Move to previous link

If you want to copy and paste text from pages then you can switch to “Caret Browsing” in Firefox with <F7>. Firefox will display a cursor on new pages that you can move and select with. Selection is possible in the same way as normal text-editors i.e. with the arrow and shift keys.

An abundance of shortcuts

There are lots more useful keyboard shortcuts in Firefox. Here are the ones that I get most utility from.

Key Action
<F7> Turn on Caret Browsing
<F6> Jump from Location bar to text or back again
<Ctrl+l> Jump to firefox Location bar
<Ctrl+k> Jump to the search bar
<Shift+F10> Open the context menu (when link) selected, or
open search engine menu when the search bar is selected
<Ctrl+b> open bookmark search tool-bar
<Ctrl+h> open history search tool-bar
<Ctrl+d> bookmark current page
<Ctrl+t> Open a new tab
<Ctrl+w> Close tab
<Ctrl+Shift+w> Reopen closed tab
<Ctrl+TAB> Move to next Firefox tab
<Ctrl+Shift+TAB> Move to previous Firefox tab
<Ctrl+9> Move to the right-most Firefox tab

Mouse vs. Keyboard

Compared to mouse based actions for the same searches, the time I personally take is dramatically reduced. Obviously this depends on your normal usage of a browser and how comfortable you are with the keyboard. For me, it’s a super combination.

Posted in Productivity | Tagged , , , | Leave a comment

Xah Emacs tutorial

In order to gain at least minimal understanding of the emacs debug messages, I need some information on Lisp. I’ve read that the notation is similar to that which I’ve seen used in calculators (Reverse Polish Notation). The difference is that the operand seems to be at the start instead of the end of the sequence.

Sure enough firing up Wikipedia shows that Polish Notation exists and the article even mentions lisp.

I came across a neatly laid out tutorial that I’m going to try to work through over the next few days. My notes from the first part are below for my benefit. Take a look at the original page for the real goodies.

I’m not sure if there are differences in the elisp syntax for this variant of Emacs, but the tutorial appeals to me. It’s orderly and easy to read, with examples for everything.

Notes

  • operators before arguments within brackets e.g. (fun arg1 arg2)
  • print something in the message buffer (message formatstring args...)
  • use the following command to evaluate expressions C-x C-e or ielm (the interactive command line)
  • expt = exponential
  • function name ending in p = predicate = return = t or nil
  • only nil and () are false; everything else returns true
  • not equal operator : /= (for numbers only)
  • comparison functions:
    • string-equal
    • equal : statues mismatch also results in nil
    • to set global variable use (setq var1 val1 var2 val2 ...)
    • to set local variable use:
      • ((let var1 var2) (setq var1))
      • (let ((var1 val1) (var2 val2)) (...))
    • (if ‹test› ‹true body› ‹false body›)
    • group a block of expressions with (progn (exp1) (exp2))
    • (while ‹test› ‹body›)
    • no for loop exists in elisp syntax
    • (defun ‹function name› (‹param1› ‹param2› …) "‹doc string›" ‹body›)
      • add (interactive) after the doc string to make the function available with <M-x> <function name>
      • interactive has up to 30 args. Most useful as follows:
        • (interactive "r") passes current text selection begin/end position as arguments
        • (interactive "n") number prompt e.g. (interactive "nWhat is your age?")
        • (interactive "s") prompt user for a string as argument.

Posted in Programming | Tagged , , | Leave a comment

Argh… Emacs/Win7 and Perl …

I’ve recently converted to using Emacs in work and home. I like the idea of the extensibility and of all the preloaded packages. Unfortunately, it has a steep learning curve when trying to configure the details. I’m still impressed but it can be a little challenging to get info on Win7 usage.

I’ve found lots of information from EmacsWiki and an exemplary blog called Emacs-fu. I’m actually pretty happy with the basic set-up but I did decide to install the latest version of orgmode and org2blog. I also installed built and installed w3m in order to read html mail through the built in gnus package. At this point I was feeling very self-satisfied and convinced that I was ready to begin programming.

I thought I would start with something simple….

Perls of wisdom

I use perl a lot on the job. As a rough but powerful tool, nothing beats it. I have never used Emacs with perl except as an editor and I didn’t want to spend too much time on the task of customization until I get a feel for what’s possible The following lisp function on perlmonks gave me a start. It starts the perl syntax check in a separate buffer with the error messages… very neat.

The rocky road to enlightenment

I had problems with Perl syntax checking. I was getting locale warnings but soon found some useful input on Stack Exchange. After setting LC_ALL (to de_DE in my case), the warnings disappeared

Execution is everything

Ok, so now I’m able to check the syntax but what about running. Both M-! and M-x shell allow me to call the perl interpreter but when I call a script it freezes the buffer. Keys are echoed but I get nothing useful back…. Very annoying. Another look at the stack exchange entry provides the answer. NUL is required. But why?

Open points…

I tried to figure this out in 30 min and it wasn’t enough. The M-x compile function has the same problem as shell and eshell. I also want to find out how to get the errors parsed so that the next error function works with the interpreter output. I’m going to leave that for another time.

Update 2013-01-27 So

I found a reference on how to run the perl debugger here. ‘M-x perldb’ prompts for input with Run perl like this: perl -d <script name>. It opens a new buffer for the output and shows a cursor mark on the original script to show the current line of execution. It’s also possible to remove the -d flag to capture script output but it’s definitely a kludge.

Posted in Programming | Tagged , , , , | Leave a comment