emacs

How can I emulate Vim's * search in GNU Emacs?

In Vim the * key in normal mode searches for the word under the cursor. In GNU Emacs the closest native equivalent would be: C-s C-w But that isn't quite the same. It opens up the incremental search mini buffer and copies from the cursor in the current buffer to the end of the word. In Vim you'd search for the whole word, even if you ...

How to sum a list of numbers in Emacs Lisp?

This works: (+ 1 2 3) 6 This doesn't work: (+ '(1 2 3)) This works if 'cl-*' is loaded: (reduce '+ '(1 2 3)) 6 If reduce were always available I could write: (defun sum (L) (reduce '+ L)) (sum '(1 2 3)) 6 What is the best practice for defining functions such as sum? ...

Emacs Lisp: How to sum odd numbers in a list?

I'd like to find elisp's analog of: sum(n for n in numbers if n % 2) # Python numbers.select { |n| n % 2 != 0 }.inject { |a, b| a + b } # Ruby Imperative way: (defun oddp (number) (not (= (mod number 2) 0))) (defun sum-odd-with-dolist (list) (let ((acc 0)) (dolist (item list acc) (if (oddp item) (setq acc (+ ...

Better control over emacs windows

I spend a lot of my time in emacs, and for the most part it's wonderful. But one thing really drives me nuts when I'm deep in it, and that's control over which window various new buffers are opened in. When I do find-file, it always opens in the current window, and this is what I like. But tons of other modes like to split my windows for...

Should I switch from vim to emacs, and if so any suggestions?

First of all, I love vim. I have been using vim for a few years now and it has changed my perceptions of what an editor is capable of. I also love modes. However I am thinking of switching and here is why: I really like Xcode and it has emacs bindings. I use Mac OS X and it has emacs functionality in all text input fields. I hate using...

How do I stop auto-formatting in emacs cperl mode?

When I do indent-region in cperl-mode if ($x) { next; } Emacs reformats it to: if ($x) { next; } How can I make it stop doing that? Note: the question originally said that this reformatting happens when yanking. I have yank setup to indent-region as well. ...

How do I do closures in Emacs lisp?

I'm trying to create a function on the fly that would return one constant value. In JavaScript and other modern imperative languages I would use closures: function id(a) { return function() {return a;}; } but Emacs lisp doesn't support those. I can create mix of identity function and partial function application but it's not sup...

Using Emacs to indent (shift 4) code

I edit my StackOverflow answers and questions with ViewSourceWith and Emacs. Often, I include code and StackOverflow formatting rules say that it must be indented by four spaces to be recognized as such. Doing it by hand or even with macros is painful. I searched in SO's previous postings but found nothing. Starting from the Python mod...

Remotely Programming

I'm doing my development work on my Windows machine, but my compiling on a remote Linux machine. What I currently do is start an X server on Windows, ssh into the Linux machine, then do the development remotely. What I'd like to do is edit my source on the Windows machine, and have it automatically copy files over to the Linux system w...

Option or Command key as Meta key for LispBox on Macintosh

I'm new to emacs and have just downloaded LispBox (from the Practical Common Lisp page) with SBCL to my Macintosh. I do know enough to realize I want either the option or Command key to be the meta key. The emacs version delivered with LispBox doesn't pay attention to .emacs in my home directory. Emacs as delivered with LispBox fires ...

How do I get a list of Emacs lisp non-interactive functions?

How do I get a complete list of non-interactive functions that I can use in Emacs Lisp? The interactive ones are easy enough to find in the help system, but I want a complete list of all the other functions I can use. For example concat, car, cdr, etc. (And preferably with documentation). Thanks Ed Edit: Answered thanks to Jouni. ...

How do I access the contents of the current region in Emacs Lisp?

I want to access the contents of the current region as a string within a function. For example: (concat "stringa" (get-region-as-string) "stringb") Thanks Ed ...

Can I change emacs find-file history

When I call find-file to open a new file, it generally happens that the file I'm looking for is in one of the directories I've already loaded from. Ideally, I'd like to scroll through the history using the up/down arrows. The problem with this is that if I've already loaded 10 files from a directory, I first have to pass through those ...

emacs function to wrap text with printfs

Some lanaguages, like Perl, support printing preformatted code: print <<EOL a line another line and another. EOL Some languages don't. For the ones that don't, I'd like to be able to write my text and then convert it to a bunch of printfs: printf "a line\n"; printf "another line\n"; printf "and another\n"; What's a good w...

How do decode URL in Emacs Lisp?

I know there's got to be a built-in function to decode a URL-encoded string (query string) in Emacs Lisp, but for the life of me I can't find it today, either in my lisp/ folder or with google. Anybody remember what it's called? ...

How to replace a character with a newline in Emacs

In Emacs, I tried to replace a character say ";" with a new line using replace-string and/or replace-regexp. Below commands are what I have tried. M-x replace-string ; \n (will replace ";" with 2 characters "\n" ) M-x replace-regex ; \n ( get below error from minibuffer ) Invalid use of `\' in replacement text. Is there anythin...

How do you pass arguments (I.E. the binarys name) to the Emacs gdb command?

Right now, I have F5 set to start gdb in emacs for me: (global-set-key [f5] 'gdb) This switches to the mini-buffer, which I then type a path to an executable... I'd like to find a way to bypass this path typing... I wrote an executable that looks at the Makefile, parses it and figures out the full path of the executable and prints it ...

emacs command to insert and indent line above cursor

I frequently find myself typing on a line, when I realize I need(ed) a variable definition (or something similar) on the line above. What I would like is to press C-return from anywhere on a line and have the cursor move to a newly inserted blank line above, with correct indentation (or at least the same as the original line). be able...

How do I get my emacs to *always* use 6x13 on X11

I recently declared .emacs bankrupcy and reorganized my init stuff. In the process, I ripped out all the hacky font selection stuff I had accrued over the years, figuring there are probably easier ways to accomplish what I want in the most modern version of emacs. GNU Emacs 23.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.14.4) on a GNU/Lin...

Emacs - Highlight buffer modifications

It often occurs that a file buffer is modified (duh!). Before exiting, emacs asks whether to save the changes. Now it would be interesting to know what actually changed. Is there a way to find out? ...