Skip to content

Instantly share code, notes, and snippets.

View Fuco1's full-sized avatar
🕶️
Configuring Emacs

Matus Goljer Fuco1

🕶️
Configuring Emacs
View GitHub Profile
@Fuco1
Fuco1 / config.el
Created January 30, 2013 18:33
Default SP config
;; predicates... I'm not sure yet how to call it. I don't want the
;; -p suffix, because that's used internally and there migth be
;; some clashes. I think sp-pred- is a good indicator, at least
;; for the built-in stuff.
(defun sp-pred-in-string (id action context)
"Return t if point is inside string or comment, nil otherwise."
(eq context :string))
(defun sp-pred-in-code (id action context)
@Fuco1
Fuco1 / slice-dash.el
Created February 23, 2013 19:36
-slice for dash
(defun -slice (list &optional from to)
"Return copy of LIST, starting from index FROM to index TO.
FROM or TO may be negative"
(setq from (or from 0))
(setq to (or to 0))
(let ((from-list list)
(result-list nil)
(index 0)
(len 0))
(cond
@Fuco1
Fuco1 / key-customize.el
Created April 6, 2013 20:10
key-customize
(defcustom sp-base-key-bindings nil
"A default set of key bindings for commands provided by smartparens.
Paredit binding adds the paredit bindings to the corresponding
smartparens commands. It does not add bindings to any other
commands, or commands that do not have a paredit counterpart.
Smartparens binding adds bindings to most common smartparens
commands. These are somewhat inspired by paredit, but in many
cases differ.
@Fuco1
Fuco1 / dyneval.el
Created April 7, 2013 19:25
Dynamic evaluation of forms with definition replacement.
(defun my-find-function-subs-arguments (form)
;; first thing in form is the function name
(let ((name (symbol-name (car form)))
(cur-param-index 1)
args cur-param-name)
(save-excursion
(goto-char 1)
(re-search-forward (concat "(defun " name))
;; replace the arguments. The next form is the argument form
@Fuco1
Fuco1 / let.el
Last active December 17, 2015 10:09
let/let* transformation
(defun my-let-to-let* ()
(interactive)
(save-excursion
(while (and (sp-beginning-of-sexp '(4)) (not (string-prefix-p (or (word-at-point) "x") "let"))))
(sp-forward-sexp)
(if (looking-back "\\*")
(delete-backward-char 1)
(insert "*"))))
@Fuco1
Fuco1 / hide-prefix.el
Created August 21, 2013 17:37
Work in progress on prefix-hiding, if someone wants to mess with it.
cl--foo
cl-loop
(setq hide-prefix-last-point (cl-remove-if foo bar))
("\\_<\\(cl--\\)\\(\\(\\sw\\|\\s_\\)+\\)"
(1 (progn (my-hide-prefix (match-beginning 1) (match-end 1)) nil))
(2 font-lock-constant-face))
@Fuco1
Fuco1 / git-ls-files.el
Created April 12, 2014 06:24
git list files
(defun my-dired-insert-git-ls-files (path)
(let* ((full-path (file-truename path))
(default-directory path)
(buf (with-current-buffer (get-buffer-create " git-ls-files")
(erase-buffer)
(current-buffer))))
(call-process "git"
nil
buf
nil
(let* ((plist1 '(:a 1 :b 2))
(plist2 '(:b 3 :c 4))
(both (-concat plist1 plist2))
(-compare-fn (-on 'equal 'car)))
(-flatten-n 1 (-distinct (-partition 2 both))))
@Fuco1
Fuco1 / text-property-api-org
Created July 26, 2014 19:44
Text property api for emacs
All these operations are very natural for buffer objects as well as
strings, which leads me to the conclusion we should provide two
flavours for each function, for buffers and for strings. The way
emacs does it is by specifying an =object= argument. I find this
suboptimal, but it is also possible solution (and would reduce the
number of functions in half). /Note that there are also different
indexing conventions, see the Question below./
All functions come in buffer and string flavours. The "current
position" is called =point= in buffer versions and =offset= in string
@Fuco1
Fuco1 / threading.el
Created August 28, 2015 21:57
Cooperative threading with generators
;; Practical cooperative threading in emacs 25 using generators.
;; Requires generator.el library of emacs 25 (can be used stand-alone
;; on anything 24.3+)
;; Eval the next three forms. To start the computation, run the
;; timer.
(fset 'foo
(iter-lambda ()
(let ((i 0))
;; limit to 3 interupts for demo purposes