# Posts Tagged emacs

From the (X)Emacs Manual:

There are commands for placing point and the mark around a textual object such as a word, list, paragraph or page.

M-@
Set mark after end of next word (mark-word). This command and the following one do not move point.
C-M-@
Set mark after end of next Lisp expression (mark-sexp).
M-h
Put region around current paragraph (mark-paragraph).
C-M-h
Put region around current Lisp defun (mark-defun).
C-x h
Put region around entire buffer (mark-whole-buffer).
C-x C-p
Put region around current page (mark-page).

M-@ (mark-word) puts the mark at the end of the next word, while C-M-@ (mark-sexp) puts it at the end of the next Lisp expression. These characters sometimes save you some typing.

Repeated M-@ extends the region forwards.

M-x describe-bindings
Lists all keybindings

Tags:

Going back to (X)emacs to code perl and c++ after a couple of years of Java coding in Eclipse I was a bit frustrated of navigating around the code with just pg-up, pg-down and search. For instance when you are looking at some function call and want to have a quick look at the definition of that function and then go back to the function call. The best way that I have discovered to do this so far is using imenu and the built in “mark” system. I set a function key to “imenu”

(global-set-key (kbd "<f3>") 'imenu)

Then with the cursor placed on the function call i press f3 RET, which then (in most cases) takes me to the function definition. When I want to go back I use the fact that imenu “sets the mark” where it left so I can use Ctrl-u Ctrl-SPC, which takes me back to the last “mark position”. First I used Ctrl-x Ctrl-x which also kind of works, but that marks the whole region from the function definition back to the function call, which is usually not what I want.

Also, repeated use of Ctrl-u Ctrl-SPC will continue going back to previous marks set in your buffer. Emacs keeps a “current buffer mark ring” in which it stores the marks that are set in the buffer. It is also good to know that “interactive search” (Ctrl-s) sets the mark where the search started when it leaves so when you have finished searching you can use Ctrl-u Ctrl-SPC to go back to where the search started. You can also manually “set the mark” by pressing Ctrl-SPC if you know this is a position you will soon want to return to.

I also like (global-set-key (kbd “C-<return>”) ‘dabbrev-expand) which kinda does code completion the simple emacs way. Since <tab> is tied up with indentation and Ctrl-space is for setting the mark I like Ctrl-Return.

Further, there are the functions ‘beginning-of-defun’/’end-of-defun’ in CPerl mode these are bound to M-C-a/M-C-e, I global-set these to C-M-right and C-M-left which are in my installation bound to beginning and end of sentence which I have no much use for.

Tags:

Ok, this is sooo cool! For us who love Perl and often have the feeling of “If I could just filter this emacs buffer through Perl, how happy I would be!” here’s a tip:

Step 1: Mark the buffer (or the parts of it that you are interested on running through Perl).
Step 2: Type M+| (“Escape” + “|” (vertical bar) on your normal keyboard) or
Step 2 (alt): Issue the “shell-command-on-region” elisp function
Step 3: Enter your perl magic, for instance ‘perl -ne “print if /gnu/”‘ to remove all lines which does not match “gnu”
Step 4: Be amazed!

Now, the result will end up in the minibuffer if it can fit on one line, otherwise a new “shell command output buffer” will be created and hold your stuff.

Tags: , , ,