Skip to content

Instantly share code, notes, and snippets.

View jordonbiondo's full-sized avatar
🤖
bzzzzzt

Jordon Biondo jordonbiondo

🤖
bzzzzzt
View GitHub Profile
@jordonbiondo
jordonbiondo / cycle_forms.el
Last active August 29, 2015 14:20
cycle lisp forms
;; because, why not?
(setq lexical-binding t)
(defmacro cycle-forms (&rest forms)
(let ((sym (make-symbol "sym"))
(n 0)
(l (length forms)))
(set sym 0)
`(case (prog1 ,sym
@jordonbiondo
jordonbiondo / cleanup-if-not-make.el
Last active November 30, 2021 06:29
clean up if not makefile
(defvar all-make-modes
'(makefile-makepp-mode makefile-bsdmake-mode makefile-imake-mode makefile-automake-mode makefile-mode makefile-gmake-mode)
"A list of the makefile major modes")
(defun my-cleanup-buffer-before-save ()
(delete-trailing-whitespace (point-min) (point-max))
(when (and (derived-mode-p 'prog-mode)
(not (member major-mode all-make-modes)))
(indent-region (point-min) (point-max))))
@jordonbiondo
jordonbiondo / auto-rvm.el
Created February 13, 2015 15:31
automatically swith rubies when changing buffer to a ruby buffer outside the current project.
;; automatically swith rubies when changing buffer to a ruby buffer outside the current project.
;; requires rvm.el and projectile
(defvar jorbi/-last-active-ruby-project nil)
(defun jorbi/maybe-activate-new-ruby ()
(when (and (equal major-mode 'ruby-mode)
(not (equal jorbi/-last-active-ruby-project
(setq jorbi/-last-active-ruby-project
@jordonbiondo
jordonbiondo / jorbi-magit.el
Created February 9, 2015 18:50
Magit, macro to define commands that change an unstaged hunk, with example.
(defun jorbi-magit/-line-region-of-section-at-point ()
"If point is in a hunk return a list of info about the hunk.
The info is like (expanded-file-name starting-line number-of-lines-show)"
(let* ((section (magit-current-section))
(context-type (magit-section-context-type section)))
(when (and (member 'hunk context-type))
(let* ((info
(mapcar 'string-to-number
(split-string
@jordonbiondo
jordonbiondo / jorbi-magit.el
Last active October 10, 2019 18:04
Magit, delete-trailing-whitespace on hunk under point.
(defun jorbi-magit/-line-region-of-section-at-point ()
"If point is in a hunk return a list of info about the hunk.
The info is like (expanded-file-name starting-line number-of-lines-show)"
(let* ((section (magit-current-section))
(context-type (magit-section-context-type section)))
(when (and (member 'hunk context-type))
(let* ((info
(mapcar 'string-to-number
(split-string
(defun battery-level ()
(string-to-number (shell-command-to-string "echo \"$(pmset -g ps | awk 'NR==2' | perl -pe 's/.*?(\\d+)%.*/\\1/')\"")))
(defvar battery-status-function 'battery-level)
(defun battery-indicator-string ()
(let* ((bat (funcall battery-status-function))
(index (cl-position-if (lambda (e) (> bat e)) '(87 75 62 50 37 25 12 7 -1)))
(symbol (nth index '("█" "▇" "▆" "▅" "▄" "▃" "▂" "▁" "!")))
(color (nth index (mapcar (lambda (c) (apply 'color-rgb-to-hex c)) (color-gradient '(.3 1 .2) '(1 .2 .1) 9)))))
@jordonbiondo
jordonbiondo / elisp-string-interpolation.el
Created January 7, 2015 20:01
elisp-string-interpolation.el
(defmacro fmt (str)
"Elisp string interpolation.
Example:
(fmt \"My name is #{user-full-name}, I am running Emacs #{(if (display-graphic-p) \\\"with a GUI\\\" \\\"in a terminal\\\".)}\""
(let ((exprs nil))
(with-temp-buffer
(insert str)
(goto-char 1)
@jordonbiondo
jordonbiondo / background-function.el
Created September 30, 2014 20:33
background function
(defmacro background-function (&rest args)
"Generates a function that runs in the background.
In order to work in Emacs single threaded environment.
The function must be broken in to steps.
See source for keywords."
(declare (indent defun) (doc-string 3))
(let* ((name (car args))
(margs (cadr args))
(docstring (when (stringp (caddr args))
@jordonbiondo
jordonbiondo / describe-hook.el
Created September 25, 2014 13:32
describe-hook
(defun guess-all-hooks ()
"Return a list of all variables that are probably hook lists."
(let ((syms '()))
(mapatoms (lambda (sym)
(if (ignore-errors (symbol-value sym))
(let ((name (symbol-name sym)))
(when (string-match "-\\(hook[s]?\\|functions\\)$" name)
(push sym syms))))))
syms))
@jordonbiondo
jordonbiondo / toggle80.el
Created September 24, 2014 19:35
toggle 80 columns edittable
(defun toggle-80-editting-columns ()
"Set the right window margin so the edittable space is only 80 columns."
(interactive)
(let ((margins (window-margins)))
(if (or (car margins) (cdr margins))
(set-window-margins nil 0 0)
(set-window-margins nil 0 (max (- (window-width) 80) 0)))))
(defun toggle-80-editting-columns-balanced ()
"Set both window margins so the edittable space is only 80 columns."