What is the difference between `global-set-key` and `define-key global-map` in Emacs

Function global-set-key is an interactive function based on define-key which you can invoke by typing M-x global-set-key. Function define-key is rather used in Lisp programs. You can look up global-set-key‘s source code with C-h f global-set-key to see that it only wraps define-key. To answer your question, there are no significant differences between them.

Emacs, how to get directory of current buffer?

Sometimes default-directory for the current buffer may be set to something other than the current directory of the file the buffer is currently visiting, in which case the solution above wouldn’t give what the asker was looking for. In such cases, you can use the file-name-directory method, like so: (file-name-directory buffer-file-name) Here is a link … Read more

How to copy to clipboard in Emacs Lisp

You’re looking for kill-new. kill-new is a compiled Lisp function in `simple.el’. (kill-new string &optional replace yank-handler) Make string the latest kill in the kill ring. Set `kill-ring-yank-pointer’ to point to it. If `interprogram-cut-function’ is non-nil, apply it to string. Optional second argument replace non-nil means that string will replace the front of the kill … Read more

let and flet in emacs lisp

Unlike Scheme, Emacs Lisp is a 2-lisp, which means that each symbol has two separate bindings: the value binding and the function binding. In a function call (a b c d), the first symbol (a) is looked up using a function binding, the rest (b c d) are looked up using the value binding. Special … Read more

What is “with-eval-after-load” in Emacs Lisp

From etc/NEWS: * Lisp Changes in Emacs 24.4 … ** New macro `with-eval-after-load’. This is like the old `eval-after-load’, but better behaved. Emacs 24.4 was released on 20th October 2014. eval-after-load is considered ill-behaved because it is a function, not a macro, and thus requires the code inside it to be quoted, which means that … Read more