This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Sequences | |
;; | |
;;; Types: | |
;; 1. list | |
;; 2. vector | |
;; 3. string | |
;; 4. bool-vector | |
;; 5. char-table | |
;; 6. `nil' | |
;; |