elisp

Why Emacs "downcase" function might refuse to do downcasing?

I'm trying to write simple Emacs function to convert ids between C style ones and camelCase ones (i.e. c_style <-> cStyle). But for some reason, Emacs built in downcase function leaves the word intact. M-x downcase-word works fine so I completely lost. Any ideas are welcome. (defun toggle-id-style () "Toggle between C-style ids and ca...

Tips for profiling misbehaving Emacs lisp?

I customize Emacs a lot. Recently, I added something to my .emacs configuration that sporadically pegs my CPU at 100%, but I really don't know what it is. If I press C-g a bunch of times, eventually I'll get a message below the minibuffer asking me if I want to auto save my files and then if I want to abort emacs entirely. If I keep sa...

why shouldn't I use a push-mark

I implemented a small function, which parses an SQL INSERT statement and highlights a column value when a cursor is on a column name and vice versa. Then I wanted to add a possibility to quickly jump between column name and column value. I used push-mark in my implementation, so I can jump with C-x C-x (exchange-point-and-mark). It wor...

How can I check if a current buffer exists in emacs?

Hi, I would like to write a function which takes action if a give buffer name already exists. For example: (if (buffer-exists "my-buffer-name") ; do something ) Does elisp have a function that will check the for the existence of a buffer similar to how my made up "buffer-exists" function does? Thanks ...

ido-switch-buffer and bury-buffer

I've recently started using ido-mode, which, overall, is pretty nice. But one thing seems especially broken, and I'm wondering if there's a setting (ha) buried in there to fix it. ido-switch-buffer doesn't seem to care about buried buffers. That is, if I use bury-buffer, and then ido-switch-buffer, the first choice is often the one I ...

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...

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...

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? ...

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...

emacs lisp, can you create interactive functions in a macro?

I'm trying to write a macro in emacs lisp to create some 'helper functions' Ultimately, my helper functions will be more useful that what I have here. I realize that there may be better/ more intuitive ways to accomplish the same thing (please post) but my basic question is why won't this work/ what am I doing wrong (defmacro deftext (...

elisp functions as parameters and as return value

I have the following code (defun avg-damp(f) #'(lambda(x) (/ (+ (funcall f x) x) 2.0))) A call (funcall (avg-damp #'(lambda(v) (* v v))) 10) returns 55.0 (the correct value) in SBCL but crashes with the following stack in emacs lisp Debugger entered--Lisp error: (void-variable f) (funcall f x) (+ (funcall f x) x) (/ (...

How can I get emacs to revert all unchanged buffers when switching branches in git?

Often, when I switch branches in git, if the files are open in emacs, then emacs asks if I want to revert them (as it thinks they've changed on disk) even though the contents are identical. Firstly I'd like to find a way for emacs to not ask me about it at all if the contents on disk are identical to those in the buffer. Secondly I'd l...

Sending email in emacs programs

Is there a way to build up an email message from a region or buffer, set up a recipient and then send a message in elisp code? I've configured emacs to send mail via my gmail account and I'd like to be able to send myself emails from elisp programs. The command used is message-mail. ...

How do I get basic App<->Emacs integration?

There are a bunch of applications out there that integrate Emacs with external processes. GDB is one that comes to mind. I can control GDB from emacs and then get feedback on the screen. I'd like to do something in that direction with my application. Here's what I want: establish a connection between me and emacs. I'd probably start ...

Why does this Emacs Lisp snippet break list-colors-display?

I like Emacs to highlight tab characters using the trailing-whitespace face, which I set to be a slightly grayer version of my background color. That way, all whitespace that I consider unwanted (tab characters and trailing whitespace) will have a slightly gray background. This is the code I use: (add-hook 'font-lock-mode-hook '(lamb...

How can I apply a new emacs C style to reformat all my source files?

I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here). How can I apply this function to all my source files at once, so that they are all formatted and indented correctly according to the Google style? ...