Memo on upgrading ArchLinux

shit happens

pacman -Syu

archlinux replace grub with grub2

I cannot install grub2, blocklists stuff

downgrade to grub-obsolete

then grub

setup (hd0) to install MBR

restart netbook (make sure the boot priority is right)

notes on upgrading Gentoo Linux

sudo emerge --update --deep --with-bdeps=y --newuse world

  • I get notified that some newer version package is required, so I have to manually install those package and re-run the emerge world
  • Some package is gone (libreoffice-bin, for example).

Here is command to manually install package:

sudo ebuild /usr/portage/www-client/firefox-bin/firefox-bin-23.0.ebuild unpack compile install qmerge clean

How to take screen shot for business people efficiently in Emacs

to take screen shot for business people efficiently in Emacs :en:emacs:screenshot:org:word:office:linux:

CREATED: <2013-10-23 Wed>

UPDATED: <2015-08-11 Tue>


Name Description Minimum version
Org-mode create org-file which could be converted to odt file 7.8
scrot command line tool to take screen shot any version
Libreoffice convert odt to Microsoft Word any version
xsel X clipboard tool any version

Work flow

Use scrot to screenshot and put its path into clipboard

scrot '%H%M%S-%d_$wx$h.png' -e 'mkdir -p ~/screenshot;mv $f ~/screenshot/;echo ~/screenshot/$f|tr -d \"\\n\"|xsel -ib;'

Create org file and insert path of screen shot

Actually I use below elisp command to do the insertion for me.

(defun insert-file-link-from-clipboard ()
  "Make sure the full path of file exist in clipboard. This command will convert
The full path into relative path and insert it as a local file link in org-mode"
  (let (str)
        ((eq system-type 'cygwin) "getclip")
        ((eq system-type 'darwin) "pbpaste")
        (t "xsel -ob"))
      (setq str (buffer-string)))

    ;; convert to relative path (relative to current buffer) if possible
    (let ((m (string-match (file-name-directory (buffer-file-name)) str) ))
      (when m
        (if (= 0 m )
            (setq str (substring str (length (file-name-directory (buffer-file-name)))))
        (insert (format "[[file:%s]]" str)))

Convert org file into Microsoft Word format

I'm sure this method works even on Windows. But I don't have Windows PC to validate my belief. Libreoffice is required.

Run the command "M-x org-export-as-odt".

Word document is automatically created if you insert below code into your ~/.emacs:

;; This setup is tested on Emacs 24.3 & Emacs 24.4 on Linux/OSX
;; org v7 bundled with Emacs 24.3
(setq org-export-odt-preferred-output-format "doc")
;; org v8 bundled with Emacs 24.4
(setq org-odt-preferred-output-format "doc")
;; BTW, you can assign "pdf" in above variables if you prefer PDF format

;; Only OSX need below setup
(defun my-setup-odt-org-convert-process ()
  (let ((cmd "/Applications/"))
    (when (and (eq system-type 'darwin) (file-exists-p cmd))
      ;; org v7
      (setq org-export-odt-convert-processes '(("LibreOffice" "/Applications/ --headless --convert-to %f%x --outdir %d %i")))
      ;; org v8
      (setq org-odt-convert-processes '(("LibreOffice" "/Applications/ --headless --convert-to %f%x --outdir %d %i"))))

Emacs will find the binary "soffice" from libreoffice to do the conversion.


If you need page break in exported document, insert below snippet into the org file:

#+ODT: <text:p text:style-name="PageBreak"/>

How to use flyspell in web-mode

to use flyspell in web-mode :en:emacs:

Please see for solution.


  • 菜谱
  • 甜面酱本身带盐了
  • 蒜苗可以大火快炒,更嫩一点


How to use git effectively

To take the full power of git, you need forget GUI and use CLI only. A little knowledge of script language like Bash/Perl/Python may be helpful.

Here is an example how I use git.


I'm working for a big enterprise project which uses git as version control software. My daily routine is find what files I changed. So I often use git commands with "–stat" paramters.

git show --stat

git diff --cached --stat

git log --stat

git diff --stat

Since I use CLI git in bash shell only. I set alias for these commands in bash. For example, I need only type gds in bash instead of "git diff –stat".

Git commands with "–stat" option usually only display relative paths, so I write some bash function which enable me select that relative path interactively (without using mouse, of course), convert that path to absolute path, and copy that absolute path into clipboard.

Getting full path into clipboard is useful because in big projects I need do lots of communication with managers and colleagues. For example, I need list files I changed in our bug tracking system (JIRA) and also email them by using Outlook. If you still don't understand why it's hard in big project, let me give you some hint. Big project is usually a big shit. Say you will edit file A, you will find another 10 files distributed in different location with same file name and similar code. Those another 10 files are not your business and if you dare touch them, you need deal with another 10 managers from ten teams.

Set up

Now you understand the problme. Here comes the solution.

Step 1, You need install percol by sudo pip install percol. Percol will provide some interactive UI to help you select the line in shell.

Step 2, install xsel or xclip under Linux to support paste text into X clipboard. BTW, you did install some clipboard manager under Linux, didn't you?

Step 3, insert below code into your ~/.bash:

# search the file and pop up dialog, then put the full path in clipboard

function pclip() {
    if [ $OS_NAME == CYGWIN ]; then
        putclip $@;
    elif [ $OS_NAME == Darwin ]; then
        pbcopy $@;
        if [ -x /usr/bin/xsel ]; then
            xsel -ib $@;
            if [ -x /usr/bin/xclip ]; then
                xclip -selection c $@;
                echo "Neither xsel or xclip is installed!"

function glsf () {
    local str=`git --no-pager log --oneline --decorate --stat $* |percol`
    if [[ $str =~ ^[[:space:]]*([a-z0-9A-Z_.\/-]*).*$ ]]; then
        echo -n ${BASH_REMATCH[1]} |pclip;
        echo ${BASH_REMATCH[1]}

function ff()

    # @see
    local fullpath=$*
    local filename=${fullpath##*/}
    local filter=${fullpath##*./}
    #  only the filename without path is needed
    # filename should be reasonable
    local cli=`find $PWD -type f -iname '*'${filename}'*'|grep ${filter}|percol`
    echo ${cli}
    echo -n ${cli} |pclip;



ff line-from-clipboard

# now I can paste the full path into firefox, outlook ...

Here is the screen cast:





1: 三文鱼去掉鱼骨,拔出鱼刺,和豆腐切成大小相仿的小块,




2: 其他材料备好;


3: 锅底用姜片擦一遍,放入姜片、三文鱼2面煎黄取出,



4: 倒入适量老抽上色,生抽、盐、糖、大蒜调味,



5: 放入甜椒块翻炒一下,撒入松子、香菜段即可起锅。







  • 生抽至少两大勺,我放得太少
  • 炖得时候我放水太少,一开始就要多放,至少半大碗水
  • 鱼和豆腐煎的黄一点,一开始用纸吸干水份较好,否则油到处溅
  • 老抽没有了,所以颜色很难看
  • 诀窍1,黑胡椒之类的辛香料都是油炸过后才更香
  • 诀窍2,如果做汤的话,鱼和豆腐炖的时间越长越好吃,也有营养


Copy file name or full path of file from Emacs dired buffer into system clipboard

Simple, insert below code into your ~/.emacs:

;; {{ copy the file-name/full-path in dired buffer into clipboard

;; `w` => copy file name

;; `C-u 0 w` => copy full path

(defadvice dired-copy-filename-as-kill (after dired-filename-to-clipboard activate)
    (insert (current-kill 0))
    (shell-command-on-region (point-min) (point-max)
                              ((eq system-type 'cygwin) "putclip")
                              ((eq system-type 'darwin) "pbcopy")
                              (t "xsel -ib")
  (message "%s => clipboard" (current-kill 0))

It support Cygwin and OSX out of the box. You need install xsel under Linux.

BTW, I suggest installing a clipboard manager like parcellite under Linux to sync the two X clipboards.


  • 放蒜(可以加姜,葱)大火爆炒,也可以加点老抽
  • 放入番茄超出茄红素
  • 加水煮,调味放盐糖
  • 最后放入打碎鸡蛋,五秒钟后起锅


Matthew Keeler video tutorial on org-mode in Emacs

At 4:57 it becomes interesting.