Skip to content

Instantly share code, notes, and snippets.

View xuchunyang's full-sized avatar

Xu Chunyang xuchunyang

View GitHub Profile
@xuchunyang
xuchunyang / elisp-macro-demo.el
Created March 25, 2015 09:52
elisp-macro-demo.el
;;; Example 1
(defmacro inc (var)
(list 'setq var (list '1+ var)))
(macroexpand '(inc a))
==> (setq a (1+ a))
(defmacro inc2 (var1 var2)
(list 'progn (list 'inc var1) (list 'inc var2)))

Messy notes for org-mode

Tasks

@xuchunyang
xuchunyang / elisp-pcase-note.el
Created April 1, 2015 13:47
elisp-pcase-note.el
;;; elisp-pcase-note.el --- Learning Notes for Pattern Matching implemented in Emacs Lisp
;; URL: http://www.emacswiki.org/emacs/PatternMatching
;; Created: Wed Apr 1 20:57:16 CST 2015
;;; Find the reciprocal of a number
(defun recip (n)
(pcase n
(`0 (error "Can't divide by zero"))
(n (/ 1.0 n))))
;;; elisp-parse-xml.el --- demo for parse xml in Emacs Lisp
;;; Created: 2015/04/01
;;; URL: $gist_url$
(insert-file-contents "~/ss.xml")
;; ==>
;; <?xml version="1.0" encoding="UTF-8"?>
;; <note>
;; <to>Tove</to>
@xuchunyang
xuchunyang / elisp-process-demo.el
Created April 3, 2015 15:55
elisp-process-demo.el
;;; Emacs Lisp Process
(call-process "pwd" nil t nil)
(call-process "grep" nil "bar" nil "root" "/etc/passwd")
(let ((default-directory "/tmp/"))
(call-process "pwd" nil t))
(call-process-region 1 6 "cat" nil t)
;;; Demo 1
;;; `candidates' is a real list
(setq simple-helm-source
'((name . "A simple source")
(candidates . (1 2 3 4))
(action . (lambda (candidate) (message "%s" candidate)))))
(helm :sources '(simple-helm-source))
@xuchunyang
xuchunyang / elisp-helm-demo-02.el
Last active August 29, 2015 14:18
helm demo 02
;;; elisp-helm-demo-02.el --- Write helm extensions demo 02
;; Demo 01 --- with matched got highlighted with `helm-build-in-buffer-source'
(setq a-helm-source
(helm-build-in-buffer-source "*a helm source*"
:init (lambda ()
(let ((text (buffer-string)))
(with-current-buffer (helm-candidate-buffer 'global)
(insert text))))
:real-to-display (lambda (cand) (upcase cand)) ; Real displayed stuff
;;; elisp-minor-mode.el --- Write Minor Mode
;;; Commentary:
;;
;; See Info node `(elisp) Minor Mode'
;;; `foo-mode' variable and functions, `foo-mode-hook' are define via this macro.
(define-minor-mode foo-mode
"Foo minor mode."
;; The initial value.
(setf (buffer-string) (buffer-name))
(setf (mark) 10
(point) 20)
(setq my-list '(0 1 2 3 4 5))
(cl-letf ((my-list))
(message "%s" my-list)) ;; ==> "(0 1 2 3 4 5)"
@xuchunyang
xuchunyang / elisp-sequence.el
Last active August 29, 2015 14:19
elisp-sequence.el
;;; Sequences
;;
;;; Types:
;; 1. list
;; 2. vector
;; 3. string
;; 4. bool-vector
;; 5. char-table
;; 6. `nil'
;;