Skip to content

Instantly share code, notes, and snippets.

View davazp's full-sized avatar

David Vázquez Púa davazp

View GitHub Profile
@davazp
davazp / magit-cleanup.el
Created January 27, 2016 14:37
Cleanup whitespaces in a magit diff hunk
(defun davazp/magit-cleanup-hunk-whitespace ()
"Cleanup the whitespaces in the diff hunk under the cursor."
(interactive)
(let ((current (magit-current-section)))
(when (eq 'hunk (magit-section-type current))
(let ((file (magit-file-at-point))
(context (caddr (magit-section-value current))))
(cl-destructuring-bind (first-line count)
(mapcar #'string-to-number (split-string context ","))
@davazp
davazp / sql-autoupcase.el
Created December 11, 2015 14:31
Upcase SQL keywords
;;; sql-autoupcase.el --- Minor mode for upcasing SQL keywords -*- lexical-binding: t; -*-
;; Copyright (C) 2015 David Vazquez
;; Author: David Vazquez <davazp@gmail.com>
;; Keywords: abbrev, convenience, languages
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
@davazp
davazp / ffap-nodejs-module.el
Created September 18, 2015 13:06
Find node module at point
;;; Try to find the string at point as a NodeJS module
(require 'ffap)
(defun ffap-nodejs-module (name)
(unless (or (string-prefix-p "/" name)
(string-prefix-p "./" name)
(string-prefix-p "../" name))
(let ((base (locate-dominating-file
default-directory
@davazp
davazp / switch-to-other-buffer.el
Created August 26, 2015 17:31
switch-to-other-buffer
(defun switch-to-other-buffer ()
"Switch to the most recently visited buffer. Calling this
command repeatly will switch between the last two most recent
buffers."
(interactive)
(switch-to-buffer (other-buffer)))
(define-key global-map (kbd "C-;") 'switch-to-other-buffer)
/* KBDUS means US Keyboard Layout. This is a scancode table
* used to layout a standard US keyboard. I have left some
* comments in to give you an idea of what key is what, even
* though I set it's array index to 0. You can change that to
* whatever you want using a macro, if you wish! */
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
@davazp
davazp / gist:5522582
Created May 5, 2013 23:32
JSCL destructuring-bind macroexpansion
(destructuring-bind ((var count &optional result) &body body)
list
nil)
;; =>
(LET* ((#:G19046 (VALIDATE-REQVARS LIST 1))
(#:G19047 (VALIDATE-REQVARS (CAR #:G19046) 2))
(VAR (CAR #:G19047))
(COUNT (CAR (CDR #:G19047)))
@davazp
davazp / erc-emph.el
Created December 13, 2012 18:33
Emphatize text in ERC
(defun erc-emphatize ()
(when (eq erc-interpret-controls-p t)
(goto-char (point-min))
(while (re-search-forward "\\(?:^\\|\\s-\\)\\*\\([^*]+\\)\\*\\(:?$\\|\\s-\\)" nil t)
(replace-match "\C-b\\1\C-o" nil nil))
(goto-char (point-min))
(while (re-search-forward "\\(?:^\\|\\s-\\)_\\([^_]+\\)_\\(?:$\\|\\s-\\)" nil t)
(replace-match "\C-_\\1\C-O" nil nil))
(goto-char (point-min))
(while (re-search-forward "\\(?:^\\|\\s-\\)/\\([^/]+\\)/\\(?:$\\|\\s-\\)" nil t)
@davazp
davazp / gist:4115013
Created November 20, 2012 00:01
Gists url handlers for GNU/Emacs
;;; URL handlers for Gists
(defvar gist-directory
"~/.gists/")
(defvar gist-url-regex
"^https://gist.github.com/\\(.*\\)$")
(defun gist-retrieve (id)
(unless (file-exists-p gist-directory)