Skip to content

Instantly share code, notes, and snippets.

View redguardtoo's full-sized avatar
⛸️
Focusing

Chen Bin redguardtoo

⛸️
Focusing
View GitHub Profile
@jplindstrom
jplindstrom / evil_defun_textobject.el
Created September 13, 2012 13:41
A "defun" Emacs Evil text object
;; Define a "defun" Emacs Evil text object
(defun jpl-line-before-end-of-defun (&optional arg)
(interactive)
(end-of-defun arg)
(previous-line))
(defun jpl-line-after-beginning-of-defun (&optional arg)
(interactive)
(beginning-of-defun arg)
(next-line))
@icholy
icholy / gobreak.sh
Last active December 16, 2015 19:18
Shell script to simplify setting GDB breakpoints
# Demo http://ascii.io/a/3019
# build
gdbb () {
# build with debug flags
go build -gcflags "-N -l" -o out
# make sure the build didn't fail
if [ $? != 0 ]; then return; fi
@redguardtoo
redguardtoo / .ctags.sample
Last active January 20, 2025 03:43
my ~/.ctags. Please note this is configuration for Exuberant Ctags. If you use Universal Ctags, you need run `ctags --options="$HOME/.ctags" -e -R` in shell at least once and fix all the warnings.
--c++-kinds=+p
--fields=+iaS
--extra=+q
--exclude=*/.hg/*
--exclude=.hg/*
--exclude=*/.cvs/*
--exclude=.cvs/*
--exclude=*/.svn/*
--exclude=.svn/*
--exclude=*/.git/*
@druska
druska / native_js_drag_and_drop_helper.js
Created August 26, 2015 03:56
Create the `simulateDragDrop` function which can be used to simulate clicking and dragging one DOM Node onto another
function simulateDragDrop(sourceNode, destinationNode) {
var EVENT_TYPES = {
DRAG_END: 'dragend',
DRAG_START: 'dragstart',
DROP: 'drop'
}
function createCustomEvent(type) {
var event = new CustomEvent("CustomEvent")
event.initCustomEvent(type, true, true, null)
@bsuh
bsuh / faster_readbyte_from_file.diff
Created September 11, 2015 20:54
Faster reading of bytes from files in Emacs
diff --git a/src/lread.c b/src/lread.c
index e1a4b33..4f17e39 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -467,7 +467,7 @@ readbyte_from_file (int c, Lisp_Object readcharfun)
}
block_input ();
- c = getc (instream);
+ c = getc_unlocked (instream);
@jackrusher
jackrusher / giraffe.el
Created April 28, 2017 14:25
An example elisp function presented at Emacs Berlin
(defun giraffe ()
"Passes a the active region (highlighted text in non-emacs
speak) to an external command that produces an SVG graph of the
data, which is then placed in a buffer called *giraffe* and
viewed as an image."
;; Declare that this is an interactive command. Whenever a function
;; starts this way emacs will make it available to be called with
;; M-x or bound to a key.
(interactive)
@anachronic
anachronic / init-javascript.el
Last active August 24, 2022 13:07
A hydra for js2-refactor in emacs
(defhydra js2-refactor-hydra (:color blue :hint nil)
"
^Functions^ ^Variables^ ^Buffer^ ^sexp^ ^Debugging^
------------------------------------------------------------------------------------------------------------------------------
[_lp_] Localize Parameter [_ev_] Extract variable [_wi_] Wrap buffer in IIFE [_k_] js2 kill [_lt_] log this
[_ef_] Extract function [_iv_] Inline variable [_ig_] Inject global in IIFE [_ss_] split string [_dt_] debug this
[_ip_] Introduce parameter [_rv_] Rename variable [_ee_] Expand node at point [_sl_] forward slurp
[_em_] Extract method [_vt_] Var to this [_cc_] Contract node at point [_ba_] forward barf
[_ao_] Arguments to object [_sv_] Split var decl. [_uw_] unwrap
[_tf_] Toggle fun exp and decl [_ag_] Add var to globals
@gausby
gausby / advice-flyspell-auto-correct-word-to-read-out-loud.el
Last active November 14, 2017 15:41
Custom flyspell-insert-function that will read the word out loud
;; Read the inserted word out loud using the macOS speech synthesizer
;; when a misspelled word is corrected using the flyspell
;; `flyspell-auto-correct-word'-command.
;;
;; Note this only work on macOS. It should be fairly easy to change to
;; work with other command line interface speech synthesize systems.
;;
;; In a previous version this used to be a defadvice, but I've changed
;; it to implementing a custom flyspell insert function. This seems to
;; work a bit more reliably.
@redguardtoo
redguardtoo / .emacs
Last active May 9, 2024 14:09
minimum emacs setup for Emacs plugin testing
;; A minimum .emacs to test Emacs plugins
(show-paren-mode 1)
(eval-when-compile (require 'cl))
;; test elisps download from internet here
(setq test-elisp-dir "~/test-elisp/")
(unless (file-exists-p (expand-file-name test-elisp-dir))
(make-directory (expand-file-name test-elisp-dir)))
(setq load-path
(defun narrow-or-widen-dwim (p)
;; fixed to behave correctly in org-src buffers; taken from:
;; https://lists.gnu.org/archive/html/emacs-orgmode/2019-09/msg00094.html
"Widen if buffer is narrowed, narrow-dwim otherwise.
Dwim means: region, org-src-block, org-fixed-width-region,
org-table-field, org-subtree, or defun, whichever applies
first. Narrowing to:
- org-src-block calls `org-edit-src-code'