Use Gnus to apply patch sent by `git send-email`

Send the latest commit


# send one commit

git send-email -1 --annotate

Apply patch

Select that email, run command "M-x gnus-summary-save-article-email" whose short key is "O m" in summary buffer.

Emacs will prompt you where to save that email. Say I save it in ~/News/patch/hello.patch.


git am ~/News/patch/hello.patch

Syntax highlight of patch email

See fgeller's plugin.

Add following code to configure his plugin:


(require 'gnus-article-treat-patch)

(setq gnus-article-patch-conditions
      '( "^@@ -[0-9]+,[0-9]+ \\+[0-9]+,[0-9]+ @@" ))

香菇生滚牛肉窝蛋粥做法

  • 菜谱
  • 香菇先用冷水冲洗,然后25度温水浸泡至少1小时,浸泡后的水也要放到粥里
  • 小火1到1.5小时后粥基本烂了,不断搅拌粥
  • 牛肉最后开大火加入过一下,可能是为了避免把牛肉烧老
  • 蛋是用粥捂熟的,据说很经典的技巧,就是要蛋白和粥混在一起,但是蛋黄半熟还是完整的
  • 如果粥觉得不够味可以加盐和鲜露(家乐牌鲜露)

http://blog.binchen.org/wp-content/uploads/2013/08/wpid-beef-porridge.jpg

Use org2blog to share blog efficiently

org2blog will post items in org-mode into wordpress blog.

It makes the Emacs best blog writer in the world.

My only issue is after publishing the blog, how can I share the blog url to social network sites.

So I write a function which will automatically put the article's permanent url into clipboard:


(defun my-org2blog-post-subtree ()
  (interactive)
  ;; go to the top node which is a blog item
  ;;(outline-up-heading)

  ;; post and publish
  (org2blog/wp-post-subtree t)
  (let* ((postid (or (org-entry-get (point) "POSTID")
                     (org-entry-get (point) "POST_ID")))
         (url org2blog/wp-server-xmlrpc-url))
    (if (not postid)
        (message "This subtree hasn't been posted, yet.")
      (setq url (substring url 0 -10))
      (setq url (concat url "?p=" postid ))
      (kill-new url)
      (with-temp-buffer
        (insert url)
        (shell-command-on-region (point-min) (point-max)
                                 (cond
                                  ((eq system-type 'cygwin) "putclip")
                                  ((eq system-type 'darwin) "pbcopy")
                                  (t "xsel -ib")
                                  )))
      (message (concat url " => clipboard"))
      )))

BTW, use some clipboard manager to synchronize the X clipboards.

Install gitso v0.6 on Gentoo Linux

Gitso is a frontend to reverse VNC connections. Say you want to access your office pc which is behind firewall. Then you need Gitso.

Here is the commands to install gitso:


sudo mkdir /usr/portage/net-misc/gitso

sudo bash -c "curl -L https://github.com/longlene/clx/raw/master/net-misc/gitso/gitso-0.6.ebuild > /usr/portage/net-misc/gitso/gitso-0.6.ebuild"

sudo bash -c "curl -L https://github.com/longlene/clx/raw/master/net-misc/gitso/Manifest|sed -e '/gitso[-_]0.5/d' > /usr/portage/net-misc/gitso/Manifest"

sudo emerge wxpython iproute2 x11vnc tightvnc

sudo ebuild /usr/portage/net-misc/gitso/gitso-0.6.ebuild unpack compile install qmerge clean

There are many howtos on gitso on internet. Google it.

韩国大酱汤做法

  • 买酱,见下图

http://blog.binchen.org/wp-content/uploads/2013/08/wpid-korean-soup-sauce.jpg

  • 倒入白菜,菇,韩国豆芽等等,加冷水,煮开
  • 倒入酱,加糖盐调味

http://blog.binchen.org/wp-content/uploads/2013/08/wpid-korean-soup.jpg

How to use expand-region.el in Emacs efficiently

expand-region.el is very useful. I use it to select a code segment and keep press its expand key until the the desired region is selected.

The only issue is its recommended hotkey for "er/expand-region" is "C-=". A little bit hard to press.

After marking a region by pressing "C-=", I press "=" to expand the region and "-" to contract.

As you may have noticed, I need move the right hand to press "=" or "-" so it's not quick enough.

The solution is simple, press ",xx" to select the initial region. Keep press "x" to expand. "z" to contract region because "x" "z" is close to left hand fingers.

evil-mode and evil-leader is required to implement this.

Here is the setup:

(require 'evil)
(require 'evil-leader)
(evil-mode 1) ;; enable evil-mode

(eval-after-load "evil" '(setq expand-region-contract-fast-key "z"))
(evil-leader/set-key "xx" 'er/expand-region)

How to use expand-region.el in Emacs efficiently

expand-region.el is very useful. I use it to select a code segment and keep press its expand key until the selected region expand to the desired region.

The only issue is its recommended hotkey for "er/expand-region" is "C-=". A little bit hard to press.

After marking a region by pressing "C-=", I press "=" to expand the region and "-" to contract.

As you may have noticed, I need move the right hand to press "=" or "-" so it's not quick enough.

The solution is simple, press ",xx" to select the initial region. Keep press "x" to expand. "z" to contract region because "x" "z" is close to left hand fingers.

evil-mode and evil-leader is required to implement this.

Here is the setup:

(require 'evil)
(require 'evil-leader)
(evil-mode 1) ;; enable evil-mode

(eval-after-load "evil" '(setq expand-region-contract-fast-key "z"))
(evil-leader/set-key "xx" 'er/expand-region)

Navigate/Select html tags in Emacs

UPDATED: 2013-10-02 Wed

Navigate/select html tags is kind of difficult. I've not found any plugin which could match Vim's matchit.

The most close one in Emacs is smartparens. You can check this discussion on Google Plus to get general impression.

I use smartparens' sp-select-next-thing to select html tags. But I'm not satisified with this command because it's picky on the location of my cursor and selection of multiple html tags is buggy.

So here is my fix, the new command my-sp-select-next-thing which fix all these issues.

Screen cast: https://dl.dropboxusercontent.com/u/858862/my-sp-select-next-thing.gif

Here is the code, append it into your ~/.emacs:


;; make sp-select-next-thing works even the cusor is in the open/close tag

;; like matchit in vim

;; @return t => start from open tag; nil start from close tag

(defun my-sp-select-next-thing (&optional NUM)
  (interactive "p")
  (let ((b (line-beginning-position))
        (e (line-end-position))
        (char (following-char))
        (p (point))
        rbeg
        rend
        (rlt t)
        )
    ;; "<" char code is 60
    ;; search backward
    (if (not (= char 60))
        (save-excursion
          (while (and (<= b (point)) (not (= char 60)))
            (setq char (following-char))
            (setq p (point))
            (backward-char)
            )
          )
      )
    ;; search forward
    (if (not (= char 60))
        (save-excursion
          (while (and (>= e (point)) (not (= char 60)))
            (setq char (following-char))
            (setq p (point))
            (forward-char)
            )
          )
      )
    ;; do the real thing
    (when (and (= char 60) (< p e))
      (goto-char p)
      (forward-char)
      (if (= (following-char) 47)
          (progn
            ;; </
            (backward-char)
            (setq rlt nil)
            )
        (progn
          ;; < , looks fine
          (backward-char)
          (setq rlt t)
          )
        )
      (sp-select-next-thing)
      (setq rbeg (region-beginning))
      (setq rend (region-end))

      (while (> NUM 1)
        ;; well, sp-select-next-thing is kind of wierd
        (re-search-forward "<[^!]")
        (backward-char 2)
        (sp-select-next-thing)
        (setq rend (region-end))
        (setq NUM (1- NUM))
        )
      (push-mark rbeg t t)
      (goto-char (1-rend))
      )
    rlt
    )
  )

Navigation is easy. After selelcting the tags, press "C-x C-x" to move the focus. That's it.

For evil-mode, I write some code which simulate the famous matchit in vi:


(require 'evil)



;; {{ evil-matchit

(defun my-evil-jump-item-enhanced-for-html ()
  (interactive)
  (if (or (eq major-mode 'html-mode)
          (eq major-mode 'xml-mode)
          (eq major-mode 'nxml-mode)
          )
      (progn
        (if (not (my-sp-select-next-thing 1)) (exchange-point-and-mark))
        (deactivate-mark)
        )
    (progn
      (evil-jump-item)
      )
    )
  )
(define-key evil-normal-state-map "%" 'my-evil-jump-item-enhanced-for-html)

;; }}

Now you can press "%" in evil to jump between tags!

Environment:

  • smartparens-1.5
  • evil-1.0.7
  • emacs-24.2.1

BTW, I also tried the web-mode-tag-match in web-mode which provided similar tag match feature.

At least now (2nd October,2013) web-mode does not support freemarker sytnax. But smartparens is more tolerant to these template syntax.

UPDATED (6th Nov, 2013): I started a new project evil-matchit which is not dependent on smartparens. Please check it out. But you can still use my old code because it support more languages.

UPDATED (9th Jan, 2014): evil-matchit is now powerful enough to replace my tricks based on smartparens.

苦瓜胡萝卜炒鸡蛋做法

  • 菜谱
  • 尽量切小丁
  • 小火煎蛋
  • 我先炒了胡萝卜

http://blog.binchen.org/wp-content/uploads/2013/08/wpid-bitter-melon-carrot-fried-egg.jpg

Take bavarian tasting platter at Bavarian Bier Cafe Parramatta

http://blog.binchen.org/wp-content/uploads/2013/08/wpid-bavarian-tasting-platter-01.jpghttp://blog.binchen.org/wp-content/uploads/2013/08/wpid-bavarian-tasting-platter-02.jpg