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 / save-buffer-advice.el
Created March 3, 2017 20:51
Automatically save write-protected files with SUDO TRAMP method
;; TODO: package this?
(defadvice basic-save-buffer-2 (around fix-unwritable-save-with-sudo activate)
"When we save a buffer which is write-protected, try to sudo-save it.
When the buffer is write-protected it is usually opened in
read-only mode. Use \\[read-only-mode] to toggle
`read-only-mode', make your changes and \\[save-buffer] to save.
Emacs will warn you that the buffer is write-protected and asks
you to confirm if you really want to save. If you answer yes,
Emacs will use sudo tramp method to save the file and then
@Fuco1
Fuco1 / org-archive-subtree.el
Created October 30, 2016 13:12
Archive subtrees under the same hierarchy as original in the archive files.
(defadvice org-archive-subtree (around fix-hierarchy activate)
(let* ((fix-archive-p (and (not current-prefix-arg)
(not (use-region-p))))
(afile (org-extract-archive-file (org-get-local-archive-location)))
(buffer (or (find-buffer-visiting afile) (find-file-noselect afile))))
ad-do-it
(when fix-archive-p
(with-current-buffer buffer
(goto-char (point-max))
(while (org-up-heading-safe))
@Fuco1
Fuco1 / foo.v
Created January 6, 2016 20:20
Groups
Variable G : Set.
Variable e : G.
Variable inv : G -> G.
Variable mult : G -> G -> G.
Infix "*" := mult.
Axiom left_id : forall x : G, e * x = x.
Axiom left_inv : forall x : G, inv x * x = e.
Axiom assoc : forall x y z : G, x * (y * z) = (x * y) * z.
@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
@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
(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 / 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
@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 / 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 / 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