Skip to content

Instantly share code, notes, and snippets.

View xuchunyang's full-sized avatar

Xu Chunyang xuchunyang

View GitHub Profile
@xuchunyang
xuchunyang / helm-with-mouse.el
Last active August 29, 2015 14:21
用鼠标执行 Helm 选项
(defun foo (prefix event)
"Select helm candidate by mouse. With PREFIX, also execute its first action."
(interactive "P\ne")
(when (helm-alive-p)
(with-helm-buffer
(let* ((posn (elt event 1))
(cursor (line-number-at-pos (point)))
(pointer (line-number-at-pos (posn-point posn))))
(helm--next-or-previous-line (if (> pointer cursor)
'next
@xuchunyang
xuchunyang / elisp-cl-lib-01.el
Created April 21, 2015 15:00
elisp-cl-lib-01.el
;;; elisp-cl-lib-01.el ---
;;;
(require 'cl-lib)
;;; Common Lisp Function Argument Lists
(cl-defun foo (a &optional b &key c d (e 17))
(message "%S %S %S %S %S" a b c d e)) ;; => foo
(foo 1 2 :d 3 :c 4) ;; => "1 2 4 3 17"
@xuchunyang
xuchunyang / elisp-advice-function.el
Created April 17, 2015 06:29
elisp-advice-function.el
;;; Advice Functions
(defun my-tracing-function (orig-fun &rest args)
"My tracing functions."
;; (message "Old buffer name" (buffer-name))
(message "ace-window called with args %S" args)
(let ((res (apply orig-fun args)))
(message "ace-window returned %S" res)
res))
@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'
;;
(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)"
;;; 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.
@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
;;; 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-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)
;;; 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>