Skip to content

Instantly share code, notes, and snippets.

View xuchunyang's full-sized avatar

Xu Chunyang xuchunyang

View GitHub Profile
@xuchunyang
xuchunyang / copy-and-paste-one-key.el
Created January 3, 2015 06:08
Copy or Paste using one and the same key ("C-c c")
;;; Copy or Paste using one and the same key ("C-c c")
(defun copy-or-paste ()
"Copy when there are selected text, paste otherwise."
(interactive)
(if (region-active-p)
(copy-region-as-kill (region-beginning) ; Copy
(region-end))
;; TODO: deactive mark/region
;; Paste
@xuchunyang
xuchunyang / demo-code-for-elisp-guide.el
Created January 14, 2015 10:54
demo-code-for-elisp-guide.el
;;; demo-code-for-elisp-guide.el --- practice code for elisp-guide
;;; Code:
;; Basic concepts
;; Buffers
(current-buffer)
#<buffer demo-code-for-elisp-guide.el>
(mapcar 'symbolp '(+ 1 "skin" nil t buffer-name))
(t nil nil t t t)
;;
;; Symbol components
;;
;; 1. Print name
;; 2. Value
;; 3. Function
;; 4. Property list
@xuchunyang
xuchunyang / init.el
Created January 24, 2015 13:57
init.el
;;; init.el --- Sample `user-init-file' for chinese-pyim dev
;; use space to indent by default
(setq-default indent-tabs-mode nil)
;; Remove trailing whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Use git version of org-mode
(add-to-list 'load-path "~/repos/org-mode/lisp")
(add-to-list 'load-path "~/repos/org-mode/contrib/lisp")
@xuchunyang
xuchunyang / osx-dictionary-realtime.el
Created January 26, 2015 14:10
osx-dictionary-realtime.el
(add-hook 'text-mode-hook
(lambda ()
;; (remove-hook 'after-change-functions #'first-line-if-changed nil t)
(add-hook 'post-command-hook 'first-line-if-changed2 nil 'local)))
(defun first-line-if-changed (beg end len)
(save-excursion
(goto-char (point-min))
(end-of-line)
(buffer-substring-no-properties (point-min) (point))))
;;; init.el -- minimum init file for debug Emacs
;;; Commentary:
;;; Code:
(setq message-log-max 10000
debug-on-error t)
;; Remap keys
@xuchunyang
xuchunyang / txt-2-csv-demo
Created January 31, 2015 05:23
Convert txt to csv (try to solve https://www.v2ex.com/t/166942)
➜ ~ cat words.txt
a[ei, ә]art.一个
an[әn, æn]art.一个
ability[ә'biliti]n.能力,才干
able['eibl]a.有才能的,能够的
➜ ~ gawk 'match($0, /(.*)\[(.*)\](.*)/, m) { print m[1], "\t", m[2], "\t", m[3] }' words.txt
a ei, ә art.一个
an әn, æn art.一个
ability ә'biliti n.能力,才干
able 'eibl a.有才能的,能够的
@xuchunyang
xuchunyang / write-helm-extensions.el
Created February 11, 2015 03:00
write-helm-extensions.el
;; URL: http://wikemacs.org/wiki/How_to_write_helm_extensions
;;
;; A list of candidates and an action
;;
(setq some-helm-source
'((name . "HELM at the Emacs")
(candidates . (1 2 3 4))
(action . (lambda (candidate)
@xuchunyang
xuchunyang / elisp-learn-eieio-1.el
Created March 11, 2015 11:50
elisp-learn-eieio-1.el
(defclass record () ; No superclasses
((name :initarg :name
:initform ""
:type string
:custom string
:documentation "The name of a person.")
(birthday :initarg :birthday
:initform "Jan 1, 1970"
:custom string
:type string