Emacs — fundanmental features

[#A] Emacs — fundanmental features

:type: Emacs

Num Item Comment
1 M-x locate-library
2 M-x list-load-path-shadows Debug conflicting installations
3 M-x find-library

Table Of Content

1 Check latest skills of emacs

./configure –with-crt-dir=/usr/lib/x86_64-linux-gnu

Item Comment
github https://github.com/languages/Emacs%20Lisp
google “emacs-related-keywords site:stackoverflow.com”
twitter 在twitter上以”emacs :en”定期搜索
sacha hua blog http://sachachua.com/blog/
Xah Lee blog

2 Org-mode in emacs    HARD

2.1 useful link

emacs – GTD实践—使用Emacs和Org-mode

2.2 org-mode publishing

2.2.1 org-mode导出html时,设置为不转义_

CLOSED: 2012-07-01 日 01:31
(setq org-export-with-sub-superscripts nil)

2.2.2 将org-mode导出成html时, 保持换行    IMPORTANT

CLOSED: 2011-11-11 Fri 11:53 方法: 在文本前后, 加上标签: #+BEGIN_EXAMPLE\#+END_EXAMPLE等

(org-defkey org-mode-map [(meta return)] 'my-org-meta-return)
(defun my-org-meta-return(&optional arg)
  (interactive "P")
  (insert "\n#+BEGIN_EXAMPLE\n\n#+END_EXAMPLE")
  (forward-line -3)
) 方法: 通过\n:t可以达到preserve line break, 不过org-mode开发者不再支持该feature了

I would argue that in fact it is a *much better* solution than a dumb
preserve-all-linebreaks setting because

  - it allows you to have normal text before and after the poem
  - it wraps the output into a paragraph with class "verse",
    so you can add CSS styling to it without changing
    other formatting
  - it is cleaner in every possible way.

- Carsten 方法: 遵循latex语法行尾添加\\, 或行之前加一个空行

在emacs中, 必要的行尾添加\\, (rr “^\\([^\\* #].*[^\\|]$\\)” “\\1\\\\\\\\”) 对于title中含有指定字符串的entry, 前后加上#+BEGIN_EXAMPLE和#+END_EXAMPLE    IMPORTANT

(defun replace-entry(entry_title)
  ;; filter entries whose title contains entry_title, then quote
  ;;  content by #+BEGIN_EXAMPLE and #+END_EXAMPLE
    (goto-char (point-min))
    (search-forward-regexp (format "^\*.*%s" entry_title))
    (forward-line 1)
    (move-beginning-of-line nil)
    ;; make sure the code is re-entrant
    (unless (string= (buffer-substring-no-properties (point) (+ 2 (point))) "#+")
      (insert "#+BEGIN_EXAMPLE\n")
      (search-forward-regexp "^\*")
      (insert "#+END_EXAMPLE\n")

2.2.3 导出时, 使用当前title作为文件名: 全选后导出即可

CLOSED: 2011-11-11 Fri 16:24

2.2.4 when export org-mode to html, don’t export entries of TODO, CANCELED    IMPORTANT

CLOSED: 2011-11-18 Fri 07:58

Exporting org-mode's entries to html is a fantastic way for knowledge sharing!

Usually entries of "TODO" "HALF" "DELEGATE" "CANCELED" "DEFERRED" are incomplete/immature knowledge.
Thus, I don't want to export them. Furthermore, after they are marked as "DONE", I'd like to export them.

Any idea for how to achieve this?
Note that org-export-exclude-tags doesn't help us, at my first glance.

Draft solution:
After checking the implementation of org-mode for this part, I found org-export-handle-export-tags function.
It determines what to be excluded when exporting, by search regexp of :\\(TAG1\\|TAG2\\|...\\): in entries' title.

Thus I override org-export-handle-export-tags, by search regexp of \\(TAG1\\|TAG2\\|...\\) with leading/tailing colon removed.

It's ugly but it works.
So my open question is what's the better solution? codesnippet

;; Don't export entries marked as todo-state, in a hack way.
;; TODO: need a better way, instead of override the default behaviour of org-export-handle-export-tags
(dolist (exclude-title-item '("TODO" "HALF" "DELEGATE" "DONE" "CANCELED" "DEFERRED"))
  (add-to-list 'org-export-exclude-tags exclude-title-item))

(defun org-export-handle-export-tags (select-tags exclude-tags)
  "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
Both arguments are lists of tags.
If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
will be removed.
After that, all subtrees that are marked by EXCLUDE-TAGS will be
removed as well."
  (remove-text-properties (point-min) (point-max) '(:org-delete t))
  (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
                                           select-tags "\\|")
         ;; (re-excl (concat ":\\(" (mapconcat 'regexp-quote
         ;;                                exclude-tags "\\|")
         ;;             "\\):"))
         ;; below two lines are hacked from above ones
         (re-excl (concat "\\(" (mapconcat 'regexp-quote
                                           exclude-tags "\\|")
         beg end cont)
    (goto-char (point-min))
    (when (and select-tags
                (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
      ;; At least one tree is marked for export, this means
      ;; all the unmarked stuff needs to go.
      ;; Dig out the trees that should be exported
      (goto-char (point-min))
      (setq beg (point))
      (put-text-property beg (point-max) :org-delete t)
      (while (re-search-forward re-sel nil t)
        (when (org-on-heading-p)
           (max (1- (point)) (point-min))
           (setq cont (save-excursion (org-end-of-subtree t t)))
           '(:org-delete t))
          (while (and (org-up-heading-safe)
                      (get-text-property (point) :org-delete))
            (remove-text-properties (max (1- (point)) (point-min))
                                    (point-at-eol) '(:org-delete t)))
          (goto-char cont))))
    ;; Remove the trees explicitly marked for noexport
    (when exclude-tags
      (goto-char (point-min))
      (while (re-search-forward re-excl nil t)
        (when (org-at-heading-p)
          (org-back-to-heading t)
          (setq beg (point))
          (org-end-of-subtree t t)
          (delete-region beg (point))
          (when (featurep 'org-inlinetask)
    ;; Remove everything that is now still marked for deletion
    (goto-char (point-min))
    (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
      (setq end (or (next-single-property-change beg :org-delete)
      (delete-region beg end))))

2.2.5 org-mode中导出html时, 使用比较好看的CSS [5/9]    IMPORTANT

CLOSED: 2010-05-21 星期五 20:42 ;; ————————– separator ————————– mess up for code block

CLOSED: 2010-05-21 星期五 01:07

(defun org-xor (a b)
 "Exclusive or."
 (if a (not b) b))

Text areas in HTML export 设置背景图片: background-image:url(‘org-background.jpg’);

CLOSED: 2010-05-20 星期四 23:32

body {
background-color: #f5f5d5 ;
font-family: Georgia, serif;
letter-spacing: -0.01em;
line-height: 1.6em;
margin-left: 10%;
margin-right: 10%;
background-image: url("org-background.jpg");
background-repeat: repeat-y;
} 设置背景色

CLOSED: 2010-05-20 星期四 22:35

body {
background-color: #f5f5d5 ;
font-family: Georgia, serif;
letter-spacing: -0.01em;
line-height: 1.5em;
} 将内容左右留出空白出来

CLOSED: 2010-05-20 星期四 23:16

2.2.6 org-mode中,添加section时,不想被导出内容的话,推荐做法是怎么样的:将相关的item加上noexport的tag即可

CLOSED: 2011-04-25 Mon 15:02

2.2.7 org mode导出的html没有换行

CLOSED: 2009-04-22 Wed 22:02
在 org 文件最前面加上:#+OPTIONS: “\n:t”
就可以了,还有更多的选项,可以看 org-mode 的info useful link

emacs org-mode org-export-as-html 换行

2.2.8 set the export level for “Table of contents”: #+OPTIONS: toc:2

CLOSED: 2010-01-31 星期日 10:54


The table of contents is normally inserted directly before the first
headline of the file. If you would like to get it to a different
location, insert the string TABLE-OF-CONTENTS on a line by itself at
the desired location. The depth of the table of contents is by
default the same as the number of headline levels, but you can choose
a smaller number, or turn off the table of contents entirely, by
configuring the variable org-export-with-toc, or on a per-file basis
with a line like

  • #+OPTIONS: toc:2 (only to two levels in TOC)
  • #+OPTIONS: toc:nil (no TOC at all)

2.2.9 设置org mode的内嵌css样式    IMPORTANT

CLOSED: 2009-04-22 Wed 22:33

2.2.10 org mode export table with css

CLOSED: 2009-09-04 星期五 22:43
Check out section 12.6.4 (Tables in HTML export) of the Org manual.

2.2.11 emacs在导出html时,不打印出org-mode的标识

CLOSED: 2011-05-28 Sat 01:02
‘ #+OPTIONS: creator:nil

2.2.12 org-mode直接导出pdf时,缺少pdflatex

CLOSED: 2011-05-20 Fri 16:10

sudo apt-get install texlive
sudo apt-get install texlive-latex-extra


latex and pdflatex on ubuntu 7.10


Org-Mode for GNU Emacs

2.2.13 org-mode publish project    IMPORTANT

CLOSED: 2010-04-18 星期日 15:37 basic use

 insert file: skill.org
 We need these different components,
- publish dynamic content (org => html)
- publish static content like scripts, images, stylesheets or even .htaccess files (org => copy).
- The third component is just for convenience and tells org to execute the former ones. useful link

2.2.14 html打印成pdf的问题 [3/3]

CLOSED: 2010-05-21 星期五 21:43 没有把背景颜色打印出来:打印设置中,设置打印颜色和背景, 但是打印出来的文件太大(3页共30MB)

CLOSED: 2010-05-21 星期五 01:09 没有把背景图片打印出来:打印设置中,设置打印颜色和背景

CLOSED: 2010-05-21 星期五 01:09 打印的表格太大时,不使用A4纸:设置Paper Size为A3

CLOSED: 2010-05-20 星期四 23:19

2.2.15 导出html时, 不要转义下划线_

CLOSED: 2010-05-21 星期五 22:19

2.2.16 when org-mode html export, change the title automatically: add “#+TITLE: XXX”

CLOSED: 2011-03-23 Wed 16:51
(defcustom org-hidden-keywords nil
“List of keywords that should be hidden when typed in the org buffer.
For example, add #+TITLE to this list in order to make the
document title appear in the buffer without the initial #+TITLE:
:group ‘org-appearance
:type ‘(set (const :tag “#+AUTHOR” author)
(const :tag “#+DATE” date)
(const :tag “#+EMAIL” email)
(const :tag “#+TITLE” title)))

2.2.17 org-mode在export as html时: flymake-get-file-name-mode-and-masks: Invalid file-name

CLOSED: 2011-09-10 Sat 18:16

 emacs - flymake and python-execute-region - Stack Overflow

解决方式: 如果是临时文件, 那么不启用flymake

(add-hook 'python-mode-hook
 (lambda ()
 ; Activate flymake unless buffer is a tmp buffer for the interpreter
 (unless (eq buffer-file-name nil) (flymake-mode t)) ; this should fix your problem
 ;; Bind a few keys for navigating errors
 (local-set-key (kbd "C-c w") 'show-fly-err-at-point) ; remove these if you want
 (local-set-key (kbd "M-n") 'flymake-goto-next-error)
 (local-set-key (kbd "M-p") 'flymake-goto-prev-error)))

;; --8<-------------------------- §separator§ ------------------------>8--
 (org-export-as-html arg 'hidden)
 (plist-get opt-plist :LaTeX-fragments)

2.3 org-mode table misc

Num Action Category Est effort Status
1 action 1 category1 3 TODO
2 action 2 category2 -1 DONE
3 action 3 category3 5 HALF
4 action 4 category4 4 TODO
5 action 15 category4 4 TODO
Summary sum = 15
Num Action Category Est effort Status
1 action 1 category1 1 TOD
2 action 2 category2 2 DONE
3 action 3 category3 5 HALF
4 action 4 category4 4 TOD
5 action 15 category4 3 TOD
Category Bugs critical bugs
New problems of feature upgrade 7 3
Existing problems of feature upgrade 7 0
Problems of hotfixes 7 0
Known issues of upgrade process as before 3 0
Problems of upgrade framework 0 0
Hardware or rare cases 3 0
Backend services problems 2 1
Special case of customer env 1 0
Sum 30 4

2.3.1 中文的table列没有对齐:使用等宽字体    IMPORTANT

CLOSED: 2010-03-21 星期日 18:14 useful link

Re: [Orgmode] An advice about stirng width in unicode
Re: [Orgmode] Align of columns is not correct if Chinese character conta

2.3.2 org-mode输入的table带表头

CLOSED: 2009-07-02 星期四 21:46
simply type |country|capital|<Enter>|-<Tab> and I get:

country capital

emacs fun

2.3.3 org-mode table sum the numbers in the current column: C-c +

CLOSED: 2010-03-31 星期三 00:38

2.3.4 org-mode sort table lines: C-c ^

CLOSED: 2010-03-31 星期三 00:34

2.3.5 Try formula of table in org-mode    IMPORTANT

CLOSED: 2010-04-07 星期三 19:07

Column/Row references can be absolute like ‘1’, ‘2’,...‘N’, or relative to the current column/row like ‘+1’ or ‘-2’.
‘0’ refers to the current row and column.
As a special case, references like ‘$LR5’ and ‘$LR12’ can be used to refer in a stable way to the 5th and 12th field in the last row of the table. a few examples
  • @2$3 2nd row, 3rd column
  • C2 same as previous
  • $5 column 5 in the current row
  • E& same as previous
  • @2 current column, row 2
  • @-1$-3 the field one row up, three columns to the left
  • @-I$2 field just under hline above current row, column 2 Range references

$1..$3 First three fields in the current row.
$P..$Q Range, using column names (see under Advanced)
@2$1..@4\(3 6 fields between these two fields.
A2..C4 Same as above.
@-1\)-2..@-1 3 numbers from the column to the left, 2 up to current row auto increment sample    IMPORTANT

CLOSED: 2010-04-01 星期四 01:33

Num Action Category Est effort Status
1 layout for 过磅管理 Flex 1 Denny & Allen
2 layout for 销售统计 Flex 3 Allen
3 layout for 销售统计 Flex 4 Allen
4 layout for 销售统计 Flex 3 Allen
Summary sum = 11, avg = 2.75

2.3.6 org-mode insert horizontal line to table: C-c -

CLOSED: 2010-03-31 星期三 00:28

2.3.7 org-mode insert horizontal row to table: C-c <RET>

CLOSED: 2010-03-31 星期三 00:30

2.4 org-mode agenda

2.4.1 agenda view doesn’t work: setq org-agenda-files    IMPORTANT

CLOSED: 2010-01-30 星期六 20:59

Agenda files

The information to be shown is normally collected from all agenda
files, the files listed in the variable org-agenda-files1. If a
directory is part of this list, all files with the extension .org in
this directory will be part of the list.

Thus, even if you only work with a single Org file, that file should
be put into the list2. You can customize org-agenda-files, but the
easiest way to maintain it is through the following commands

2.5 emacs org-habit


Name Summary
org-habit-graph-column The buffer column at which the consistency graph should be drawn
org-habit-preceding-days The amount of history, in days before today, to appear in consistency graphs.
org-habit-following-days The number of days after today that will appear in consistency graphs.
org-habit-show-habits-only-for-today If non-nil, only show habits in today’s agenda view. This is set to true by default.

2.5.1 working habit with org-mode

CLOSED: 2011-03-30 Wed 11:28 将schedule的meeting放入agenda view中,便于回顾每天做了什么    IMPORTANT

CLOSED: 2010-04-18 星期日 17:05 在diary中设置一个reminder每两周的周五进行提示

CLOSED: 2010-04-18 星期日 17:05
%%(diary-cyclic 60 15 7 2003) Renew medication
2010-4-12 Bi-Monday 14:30-15:30, 1-1 with Yubo
2010-4-13 每周三上午, 与Ming的1-1

2.5.2 org-mode: Remind the habit I want to keep in emacs    IMPORTANT HARD

SCHEDULED: 2010-04-20 星期二 CLOSED: 2010-04-22 星期四 01:02

  • workaround with diary
  • try pause.el
  • try org-habit.el

2.6 org-capture

2.6.1 emacs智能拷贝w3m和mail的内容

  CLOSED: [2012-06-22 五 21:40]
#+begin_src elisp
(require 'org-capture)
(define-key global-map "\C-cr" 'org-capture)
(setq org-capture-templates
      '(("d" "Diary" entry (file "diary.org") "* %T %?\n\n")
        ("m" "Mail" entry (file "current.org") (function capture-gnus-template))
        ("w" "Web" entry (file "current.org") (function capture-w3m-template))
        ("p" "Period" entry (file+headline "contacts.org" "秀秀--周期") "** %t\n")
        ;; ledger org-capture to add new contact
        ("c" "Contacts" entry (file "contacts.org")
         "* %(org-contacts-template-name)
:EMAIL: %(org-contacts-template-email)

(defun capture-gnus-template ()
  ;; "* %t %:subject :noexport:\n %s\n%?\n\n"
  (let ((content (buffer-string)))
    (setq content (replace-regexp-in-string "\n+$" "\n" content))
    (concat "* TODO mail: %:subject "
            (make-string 10 32) ":noexport:\n#+begin_example\n" content "\n#+end_example"))

(defun capture-w3m-template ()
  (let ((content (buffer-string)))
    (setq content (replace-regexp-in-string "\n+$" "\n" content))
    (concat "* web page: " w3m-current-title (make-string 10 32) "\n"
            w3m-current-url "\n"
            "** webcontent " (make-string 20 32) ":noexport:\n#+begin_example\n" content "\n#+end_example"))

2.7 org-mode appearance

2.7.1 org-mode中顶级目录的金黄色太刺眼: M-x customize-group -> org-faces    IMPORTANT

CLOSED: 2010-05-01 星期六 01:13

;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(org-checkbox ((t (:inherit bold))))
'(org-checkbox-statistics-todo ((t (:inherit org-todo :foreground "DarkKhaki"))) t)
'(org-level-1 ((t (:inherit outline-1 :foreground "LimeGreen"))))
'(org-level-2 ((t (:inherit outline-2 :foreground "YellowGreen"))))
'(org-level-3 ((t (:inherit outline-3 :foreground "SeaGreen3"))))
'(org-todo ((t (:weight bold))))
'(org-warning ((t (:inherit font-lock-warning-face :foreground "LightGoldenrod")))))

2.7.2 将org-mode中顶级目录的默认金黄色改为柔和色

CLOSED: 2010-05-20 星期四 20:40

2.7.3 设置图片的大小


2.7.4 org-mode中字体加粗,斜体,加下划线

CLOSED: 2009-07-02 星期四 21:54
org-mode中字体加粗 ,加下划线
This is bold italics underline Emacs-Fu
emacs fun

2.7.5 Don’t highlight change in org-mode, since too many changes for org files

CLOSED: 2011-09-17 Sat 23:01

(require 'hilit-chg)
(add-hook 'find-file-hook 'enable-highlight-changes-mode)
(defun enable-highlight-changes-mode ()
 "Enable highlight-changes-mode, with several modes excluded"
 (let ((prohibit-mode-list '("Org")))
 (make-local-variable 'highlight-changes-mode)
 (highlight-changes-mode nil) ;; first disable highlight-changes-mode
 (unless (member mode-name prohibit-mode-list)
 (highlight-changes-mode nil)
 (global-highlight-changes-mode 'passive);;record changes in passive way
 (local-set-key [(control c) (control c)] 'highlight-changes-mode);;toggle visibility
 (local-set-key [(control c) (control p)] 'highlight-changes-previous-change)
 (local-set-key [(control c) (control n)] 'highlight-changes-next-change)
 (set-face-foreground 'highlight-changes nil)
 ;; set highlight-changes's background color slightly different with the editor's background color(DarkSlateGray)
 (set-face-background 'highlight-changes "#3F2F4F4F4F4F")
 (set-face-foreground 'highlight-changes-delete nil)
 (set-face-background 'highlight-changes-delete "#686897")

2.8 # –8<————————– separator ————————>8–

2.9 org-mode group columns when exporting    IMPORTANT

CLOSED: 2010-03-21 星期日 19:23
Org tutorial for tables

N N^2 N^3 N^4 sqrt(n) sqrt<4>(N)
1 1 1 1 1 1
2 4 8 16 1.4142 1.1892
3 9 27 81 1.7321 1.3161

2.10 org-mode中即插入日期又插入时间: C-u C-c .    IMPORTANT

CLOSED: 2010-03-21 星期日 18:11

  • C-u C-c .
  • 自定义函数(insert (format-time-string “<%Y-%m-%d %H:%M>” (current-time)))

2.10.1 useful link

Custom time format
Subject: Re: [Orgmode] Setting timestamp format to English – msg#00074

2.11 Try feature of org-agenda-diary-file

CLOSED: 2010-03-21 星期日 21:38

2.12 在org-mode下,定义插入spliter的快捷键

;;插入字符串: ** ——————————- spliter ——————————-
(global-set-key [(meta p)(s)] ‘my-insert-spliter)
(defun my-insert-spliter()
(move-beginning-of-line nil)
(insert “** ——————————- spliter ——————————-\n”)

2.13 设置org-mode中tag对齐的列号

(setq org-tags-column 100);;设置对齐位置
C-u C-c C-c:tag全部对齐

2.14 在org-mode中将某个entry及其子记录向下降一级,或向上升一级    HARD


2.15 如何回顾上周做过什么: C-c a L

2.16 标记出done事件和canceled事件

(setq org-todo-keyword-faces
‘((“TODO” . org-warning)
(“DEFERRED” . shadow)
(“CANCELED” . (:foreground “blue” :weight bold))))

2.17 导出第三级某个结点时, html没有目录信息:org-export-headline-levels的默认值为3,太小    IMPORTANT

CLOSED: 2009-04-20 Mon 01:13

2.18 comment in org-mode

CLOSED: 2010-01-31 星期日 10:40

Comment lines

Lines starting with ‘#’ in column zero are treated as comments and
will never be exported. If you want an indented line to be treated as
a comment, start it with ‘#+ ’. Also entire subtrees starting with
the word ‘COMMENT’ will never be exported. Finally, regions
surrounded by ‘#+BEGIN_COMMENT’ ... ‘#+END_COMMENT’ will not be

C-c ; Toggle the COMMENT keyword at the beginning of an entry.

2.19 org-show-todo-tree: Make a compact tree which shows all headlines marked with TODO.

CLOSED: 2011-07-19 Tue 22:44

2.20 limit entry for agenda view: CATEGORY

CLOSED: 2010-01-31 星期日 10:31
#+CATEGORY: work

2.21 move to next heading same level: C-c C-f

CLOSED: 2009-11-05 Thu 23:25

2.22 快捷键

到上级标题: `C-c C-u’
C-c C-n:outline-next-visible-heading
到同级上一个标题: `C-c C-f’
到同级下一个标题: `C-c C-b’
用`C-c |’来创建表格
C-c +:求出当前列的总和

2.22.1 Moving subtrees

C-c C-x A:Move the current entry to the Archive Sibling
C-c C-x C-s:Archive the subtree starting at the cursor position

2.22.2 others

  • C-c C-v:org-show-todo-tree
  • C-c C-x b org-tree-to-indirect-buffer
  • C-c ^ + t: org-sort, by time
  • C-c < Insert a time stamp corresponding to the cursor date in the Calendar
  • C-c C-z:org-add-note
  • C-c / org-sparse-tree
  • C-c C-w org-refile

2.23 如何显示被delegate或cancel的工作

(“c” todo #(“DONE|DEFERRED|CANCELLED” 0 23 (face org-warning)) nil)

2.24 设置Entry的优先级: shift+方向键

2.25 如何对一块数据按tab键: (yas/Expand)    COMPUTER

2.26 org-mode中tag对齐: C-c C-c Enter

2.27 archive是什么意思

CLOSED: 2010-01-31 星期日 10:31
9.6 Archiving

2.28 org-mode中即插入日期又插入时间: C-u C-c .与 C-u C-c !

CLOSED: 2010-03-27 星期六 01:48

2.28.1 useful link

Custom time format
Subject: Re: [Orgmode] Setting timestamp format to English – msg#00074

2.29 org-mode fill cell with value of cell around: <S-return>    IMPORTANT

CLOSED: 2010-03-27 星期六 14:10

2.30 打开org-mode文件时,自动展开一定的层级:头部添加#+STARTUP: content

CLOSED: 2010-03-31 星期三 23:33
overview top-level headlines only
content all headlines
showall no folding of any entries
showeverything show even drawer contents
14.4 Summary of in-buffer settings

2.30.1 emacs默认将password.org.gpg的entry打开

CLOSED: 2011-03-02 Wed 15:30
‘ #+STARTUP: showeverything

2.31 org-mode show entries of logdone: In agenda view, press “v L” or C-u l.    IMPORTANT HARD

CLOSED: 2010-04-15 星期四 20:35

2.32 org-mode: search only on the heading, with content excluded: isearch-forward-regexp: ^\*.*org-mode

CLOSED: 2010-04-22 星期四 22:47

2.33 org-mode: Try drawers

CLOSED: 2010-04-22 星期四 21:51
Sometimes you want to keep information associated with an entry, but you normally don’t want to see it.

2.33.1 useful link

2.34 Don’t interpret underscore, when org export html: turn on/off TeX-like syntax for sub- and superscripts.    IMPORTANT

CLOSED: 2010-05-10 星期一 00:54
#+OPTIONS: ^:nil

2.35 列出某个entry下所有todo事件: regexp search :\*.*TODO

CLOSED: 2010-05-10 星期一 13:53

2.36 org-mode: display pictures    IMPORTANT

CLOSED: 2010-05-01 星期六 01:11

  • iimage mode

2.36.1 useful link

The iimage minor mode for Emacs

2.37 Search only the title in org-mode

CLOSED: 2010-05-20 星期四 20:40
org-sparse-tree -> regexp

2.38 将一列复制到本行末尾: Try yank-rectangle

CLOSED: 2010-05-28 星期五 17:09

yank-rectangle is an interactive compiled Lisp function in `rect.el'.
It is bound to C-x r y.
;; -------------------------- separator --------------------------

2.39 when export line line in code block, auto wrap the line: html中pre中自动换行的问题

CLOSED: 2011-03-23 Wed 17:05
父标记最好加个DIV,并设置CSS属性:word-wrap: break-word;white-space : normal;
pre {
white-space: pre-wrap; * css-3 *
white-space: -moz-pre-wrap; * Mozilla, since 1999 *
white-space: -pre-wrap; * Opera 4-6 *
white-space: -o-pre-wrap; * Opera 7 *
word-wrap: break-word; * Internet Explorer 5.5+ *
width:750px; * set width *

2.39.1 useful link

2.40 org-mode: Auto open entry of certain level

CLOSED: 2011-04-25 Mon 15:08
在头部使用#+STARTUP: showeverything, 而非#+STARTUP: overview

2.41 Emacs babel: execute code in many different languages.

CLOSED: 2011-07-14 Thu 23:18

2.41.1 useful link

2.41.2 org-babel-ruby-initiate-session: Cannot open load file: skill.org

CLOSED: 2011-07-14 Thu 23:18
Some languages have requirements on external elisp packages, (e.g. ruby
requires inf-ruby, lisp/clojure require slime, etc…).

2.42 linux平台上, when export undersore in org-mode, 如何设置不转义

CLOSED: 2011-07-29 Fri 13:29

2.43 work.org中最后几个条目, 不能上下移动: #+end_sr后面少了一个c

CLOSED: 2011-08-25 Thu 10:30

2.44 在org-mode中定义快捷键, 来只在标题中进行搜索    IMPORTANT

CLOSED: 2011-10-02 Sun 00:25

(org-defkey org-mode-map [(meta .)] 'occur-org-title)
(defun occur-org-title()
  "when regexp search, only search title of org-mode entries"
  (let (regexp)
    (setq regexp (read-string "Search org entries whose title matching regexp: " "^\\\*+ .*"))
    (occur-1 regexp 0 (list (current-buffer)))))

2.45 依靠org-rembmeber来, 保证记的notes普通人可以读懂    IMPORTANT

CLOSED: 2011-12-17 Sat 14:12

;;(“Webpage” ?w “* TODO %?\n %i\n” “current.org” “Webpages”)

(setq org-directory (concat DENNY_CONF "/org_data/"))
(setq org-default-notes-file "current.org")
(define-key global-map "\C-cr" 'org-remember)
(setq org-remember-templates
      '(("Todo" ?t "* TODO %?\n  %i\n" "current.org" bottom)
        ("Remind" ?r "** TODO %?\n  %i\n" "current.org" "Remind")
        ("Diary" ?d "* %T %?\n# 今日所学\n  %i\n# 今日趣闻\n  %i\n# 今日杂记\n  %i\n" "diary.org" bottom)

2.46 CANCELED org-mode中使用boostrap的css

CLOSED: 2012-12-19 Wed 19:30

2.47 emacs export post, with SEO: title, descrpition, keywords

CLOSED: 2014-06-04 Wed 13:37
curl “http://wordpress2.dennyzhang.com/wp-content/themes/portfolio-press/updatemeta.php?post\_id=14&meta\_key=\_aioseop\_title&meta\_value=thisisanonthertest



insert into wp_postmeta(post_id, meta_key, meta_value) values(14, ‘_aioseop_title’, ‘this is title’);
insert into wp_postmeta(post_id, meta_key, meta_value) values(14, ‘_aioseop_keywords’, ‘this is keywords’);
insert into wp_postmeta(post_id, meta_key, meta_value) values(14, ‘_aioseop_description’, ‘this is description’);

<title>My Career Path Review From A Small Media Interview | DennyZhang.com</title>
<meta name=”keywords” content=”DennyZhang Freelancer Startup iOS skills Promotion Branding” />
<meta name=”description” content=”Hi there, this is DennyZhang’s personal website. A freelancer, a indie iOS developer, a super fan of emacs, a fullstack engineer. The website is supposed to be a classroom for indie developers; a help center for freelancers” />


3 Web-browse in emacs

3.1 Why browse the Web in Emacs

CLOSED: 2009-11-22 Sun 22:45

  • Browsing is faster and less distracting
  • You can integrate it into your work
  • You can customize everything
  • You’re safe from browser exploits
  • You need less memory

3.2 Webjump in emacs

3.2.1 emacs webjump: webhost匹配时, 使用子串匹配, 而不是前缀匹配: 直接使用*XX*即可

CLOSED: 2011-09-27 Tue 18:13

3.2.2 CANCELED webjump-plus.el — supplemental Web site list for webjump (by Neil W. Van Dyke)

CLOSED: [2011-09-12 Mon 23:35]


3.3 w3m in emacs    IMPORTANT

Item Summary
C-c C-p (w3m-previous-buffer)
C-c C-n (w3m-next-buffer)
R Reload the current page
TAB Move the point to the next anchor.
B Move back to the previous page in the history.
N Move forward to the next page in the history.
c Display the url of the current page and put it into `kill-ring’.
S Query to the search engine a word.
s Display the history of pages you have visited in the session.
C-c C-t Create a copy of the current page as a new session.
. Shift to the left
, Shift to the right
M Display the current page using the external browser.
u Display the url under point and put it into `kill-ring’.
C-c C-s (w3m-select-buffer)
G Visit the web page in a new session.
<S-return> Display the page of the link in a new session.
M-x w3m-current-title 在w3m中如何得到当前网页的文件名:

3.3.1 windows上安装使用w3m: cygwin中安装w3m即可    HARD

CLOSED: 2010-04-05 星期一 10:29

3.3.2 show images in w3m: (setq w3m-default-display-inline-images t)    IMPORTANT

CLOSED: 2010-04-18 星期日 12:45 useful link

[emacs-w3m:03544] Re: display inline images for text/html using emacs-w3m (non-member post) – msg#00056 – emacs.w3m

3.3.3 设置w3m默认的每行的字符数: (setq w3m-fill-column 100)

CLOSED: 2011-10-20 Thu 22:25

3.3.4 emacs org-w3m: 拷w3m中网页时, 保存有效链接

3.3.5 调整w3m中, 网页组某个网页的位置

CLOSED: 2011-10-20 Thu 22:28
(define-key map [?\C-c ?\C-,] ‘w3m-tab-move-left)
(define-key map [?\C-c ?\C-<] ‘w3m-tab-move-left)

3.3.6 emacs-w3m开启时, 默认不之前的session, 以提高速度: (setq w3m-session-load-crashed-sessions nil)

CLOSED: 2011-10-26 Wed 21:13

3.3.7 useful link

4 BBDB mode in emacs

4.1 将bbdb导出成有头像的vcard    IMPORTANT

CLOSED: 2011-09-17 Sat 16:48

  • 将bbdb的每条记录导出成一个vcard文件
    (bbdb-vcard-export “~/exported-vcards/” t t)

  • 删除不必要的vcard文件(奇怪:bbdb-vcard-export会生成多余的vcard文件)

cd ~/exported-vcards/; rm -rf *-1.vcf

  • 针对每个vcard文件, 添加相应的PHOTO字段的二进制图片值

  • 将vcard合并成一个, 因为google只支持导入一个vcard
    cd ~/exported-vcards/; cat * > /tmp/vcard.vcf

  • 通过google contact与手机同步

4.2 [question] 在创建bbdb entry时, 保证人名不会重复

4.3 [question] bbdb发邮件进行名字或邮箱名联想时, 基于字符串子串匹配, 而不是前缀匹配

4.4 [question] emacs bbdb在第一次过滤后,如何进行第二次过滤

4.5 # –8<————————– separator ————————>8–

4.6 basic use

(bbdb-record-net record)

 添加记录, bbdb-create或者在.bbdb文件中输入c
 添加字段:C-o, 内置字段有Name, Phone, Address等

 (require 'bbdb)
 (bbdb-initialize 'gnus 'message 'w3 'vm)
 (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)

4.7 设置bbdb的数据文件


4.8 BBDB: set the default country name for the address property

CLOSED: 2010-08-21 星期六 11:10
(setq bbdb-default-country “中国”);;Default country for emacs

4.9 Emacs: Picture for bbdb

CLOSED: 2010-08-27 Fri 15:11
(load-file “~/myemacs/bbdb/bbdb-picture.el”)
(require ‘bbdb-picture) ;; picture support for bbdb
(setq bbdb-picture-path (concat CONF_HOME “emacs_stuff/bbdb_picture/”))
(setq bbdb-picture-extension “.jpg”)

4.9.1 useful link

bbdb-picture.el — picture support for bbdb

4.10 BBDB: search email alias    IMPORTANT

 CLOSED: [2011-07-30 Sat 11:01]
#+begin_src lisp
;; override built-in bbdb function to support search in the field of mail-alias
;; TODO, implement in a better way without duplicate codes
(defun bbdb (string elidep)
 "Display all entries in the BBDB matching the regexp STRING
in either the name(s), company, network address, or notes."
 (list (bbdb-search-prompt "Search records %m regexp: ")
 (let* ((bbdb-display-layout (bbdb-grovel-elide-arg elidep))
 (notes (cons '* string))
 (let (alias-notes)
 ;; search mail-alias
 (setq alias-notes (cons 'mail-alias string))
 (bbdb-search (bbdb-records) nil nil nil alias-notes nil))
 (bbdb-search (bbdb-records) string string string notes nil))))
 (if records
 (bbdb-display-records records)
 ;; we could use error here, but it's not really an error.
 (message "No records matching '%s'" string))))

4.11 Modifying the record creation process of bbdb

CLOSED: 2011-05-30 Mon 17:34

(defadvice bbdb-read-new-record (after wicked activate)
"Prompt for the birthdate as well."
(bbdb-record-putprop ad-return-value 'birthdate
(bbdb-read-string "Birthdate (YYYY.MM.DD): ")))

4.11.1 useful link

4.12 bbd查找邮箱不为空的记录

CLOSED: 2011-03-25 五 17:20
S-a: ^$
S-a: .+
S-a: .*@.*

4.13 export bbdb to the csv format by bbdb-to-outlook.el

CLOSED: 2011-03-02 Wed 18:20

4.13.1 useful link

Emacs, BBDB, and getting your contacts on the Android or iPhone | sacha chua :: living an awesome life

4.14 bbdb-search-invert-set(!): 反转搜索bbdb,即不满足条件的记录被选中

CLOSED: 2011-03-25 五 18:47
Typing ! inverts the meaning of the next search command.
Sets `bbdb-search-invert’ to t.
You will have to call this function again, if you want to
do repeated inverted searches.

4.15 将bbdb中的jpg文件转化成png文件格式, 不然与openwith有冲突

CLOSED: 2011-07-19 Tue 17:31

4.16 emacs发邮件时, 输入mail-alias时, 进行帮助联想

 CLOSED: [2011-07-30 Sat 13:53]
- mail-alias的输入联想: 使用M-/ runs the command hippie-expand
- mail-alias组的邮件输入: 使用abbrev缩写扩展的方式
#+begin_src lisp
# misc
(defun yas/expand ()

(defmacro bbdb-hashtable ()
 '(bbdb-with-db-buffer (bbdb-records nil t) bbdb-hashtable))

4.17 emacs直接回复bbdb中的人: 在*bbdb*mode中相应记录的位置输入m即可

CLOSED: 2011-06-27 Mon 11:03

4.18 emacs bbdb找出满足某个查询后,隐藏某些用户或进行二次搜索: 即combo/secondary search    IMPORTANT

CLOSED: 2011-10-20 Thu 21:19

(defun bbdb-combo (string elidep)
   (list (bbdb-search-prompt "Search records %m regexp: ")
  (bbdb string elidep 't)

(defun bbdb (string elidep &optional combo)
  "Display all entries in the BBDB matching the regexp STRING
in either the name(s), company, network address, or notes."
   (list (bbdb-search-prompt "Search records %m regexp: ")
  (let* ((bbdb-display-layout (bbdb-grovel-elide-arg elidep))
         (notes (cons '* string))
         (potential-records (bbdb-records))
         records alias-notes)
    (if combo
        ;; If in bbdb buffer, only perform check in records in current buffer
        (setq potential-records (mapcar 'car bbdb-records))
      ;; Perform check in all records of bbdb
        (setq potential-records (bbdb-records)))
    (setq alias-notes (cons 'mail-alias string))
    (setq records
           (bbdb-search potential-records nil nil nil alias-notes nil) ;; also search in notes
           (bbdb-search potential-records string string string notes nil)))
    (if records
        (bbdb-display-records records)
      ;; we could use error here, but it's not really an error.
      (message "No records matching '%s'" string))))

4.19 编写代码, 去掉bbdb中的mobile自定义字段, 而采用默认的Mobile(Phone)

CLOSED: 2011-09-16 Fri 22:44

(dolist (record (bbdb-records))
 (bbdb-record-set-phones record
 (format "{%s}" (cdr (assq 'mobile (bbdb-record-raw-notes record)))))
 (bbdb-record-phones record)
 (bbdb-change-record record nil)

4.21 CANCELED BBDB: Office shall be the default address

CLOSED: 2010-08-21 星期六 11:16

4.22 CANCELED Give hint when sending mail to alias email addresses

CLOSED: [2010-09-04 星期六 08:43]
(add-to-list 'load-path "~/myemacs/yasnippet-bundle")
(require 'yasnippet-bundle)
CLOSED: [2010-09-04 星期六 08:43]

4.23 CANCELED SplitMailUsingBbdb

CLOSED: [2011-10-02 Sun 00:42]


4.24 CANCELED bbdb修改人名时, 相应的图片名也跟着修改

CLOSED: 2012-04-22 日 20:43

4.25 CANCELED 修改emacs中google-maps: 显示自己的好友位置, 并保存小图

CLOSED: 2012-04-22 日 20:43

5 Shell in emacs

Item Summary
C-c C-u(comint-kill-input) 快速删除当前命令行
C-u M-! some_command Insert output of a command
(setq eshell-aliases-file “~/myemacs/data/filebat.alias”)

5.1 emacs shell WARNING: terminal is not fully functional: 设置PAGER环境变量

5.2 在emacs中使用zsh

CLOSED: 2012-03-02 五 21:56
(setq shell-file-name “/usr/bin/zsh”)

5.2.1 basic use

如果想要在emacs中使用zsh, 那么只能在M-x term中使用。

因为M-x shell中, 输入TAB时, 只会调用自动的补全功能, 也即查找当前可补
全的文件名或目录名,而不会像zsh那样给出更多的cli usage智能被全.

总体感觉term在emacs中可用性太差, 还是坚持用shell+manual的方式, 而不是在emacs中用zsh。

如果一定要用, 可以在M-x term中, 调用zsh。 同时加载如下lisp方法来在zsh与shell中进行切换

| (require 'shell)
| (require 'term)
| (define-key term-raw-map (kbd "C-j") 'term-switch-to-shell-mode)
| (defun term-switch-to-shell-mode ()
|   (interactive)
|   (if (equal major-mode 'term-mode)
|       (progn
|         (shell-mode)
|         (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter )
|         (local-set-key (kbd "C-j") 'term-switch-to-shell-mode)
|         (compilation-shell-minor-mode 1)
|         (comint-send-input)
|         )
|     (progn
|       (compilation-shell-minor-mode -1)
|       (font-lock-mode -1)
|       (set-process-filter (get-buffer-process (current-buffer)) 'term-emulate-terminal)
|       (term-mode)
|       (term-char-mode)
|       (term-send-raw-string (kbd "C-l"))
|       )))

5.2.2 web page: zsh completion will not work in emacs shell – Super User

5.3 自己写的emacs shell加强版

CLOSED: 2011-09-11 Sun 08:21

  • open a special shell for current file/directory, if the shell already exists switch to it.
  • hack shell command history, to load default command when shell buffer is created.

;; -*- coding: utf-8 -*-
;; File: skill.org
;; Author: Denny Zhang(denny.zhang001@gmail.com)
;; Created: 2009-08-01
;; Updated: Time-stamp: <2011-10-28 21:12:36>
;; --8<-------------------------- §separator§ ------------------------>8--
(defun open-shell-of-current-file ()
  "If current file doesn't open a shell, generate one.
 Otherwise, switch to related shell.
  (let* ((file-name (buffer-name)) shell-buffer-name)
    (if (string= mode-name "Shell")
        ;; if current buffer is a shell, switch to related file
        (pop-to-buffer (replace-regexp-in-string "\\*shell\\*-" "" file-name))
      ;; if current buffer is not a shell, create a related shell buffer
      (setq shell-buffer-name (concat "*shell*-" file-name))
      (if (get-buffer shell-buffer-name)
          (pop-to-buffer shell-buffer-name)
        (shell shell-buffer-name)
        ;; insert shell history
        (load-shell-history file-name)
        ;; send default input
        (comint-previous-matching-input "." -1)))

(defun open-shell-of-current-directory ()
  "If any file of current directory already have a related shell, switch to it
  (let* ((file-name (buffer-name))
         (shell-buffer-name (concat "*shell*-" file-name))
         (directory-name default-directory))
    (if (string= mode-name "Shell")
        ;; if current buffer is a shell, switch to related file
        (pop-to-buffer (replace-regexp-in-string "\\*shell\\*-" "" file-name))
      ;; if current buffer is not a shell, check
      ;; whether there is any shell opened by files in the directory
      (unless (get-buffer shell-buffer-name)
        (dolist (file-var (directory-files default-directory))
          (if (get-buffer (concat "*shell*-" file-var))
              (setq shell-buffer-name (concat "*shell*-" file-var))
      (if (get-buffer shell-buffer-name)
          (pop-to-buffer shell-buffer-name)
        (shell shell-buffer-name)
        ;; insert shell history
        (load-shell-history file-name)
        ;; send default input
        (comint-previous-matching-input "." -1))))
(defvar shell-history-alist '(;; erlang files
                              (".*erl" . (("make && ./start.sh")
                                          ("erlc ./%f && erl -noshell -s %s start_link")
                                          ("sudo rabbitmqctl list_queues")
                                          ("erl -mnesia dir '\"data/mnesia/\"' -name crontab_generator_app@ubuntu")
                                          ("erl -noshell -s mnesia start -s tv start")
                                          ("sudo rabbitmqctl list_queues name messages_ready messages_unacknowledged")
                              ;; ledger files
                              (".*ledger" . (("bankbal")))
                              ;; default value for any files
                              (".*" . ())
  " For the shell of one file, append user defined commands to the shell history
Each element looks like (REGEXP . COMMAND-LIST).
REGEXP is a regexp which filter filename.
COMMAND-LIST is a list of commands, which will be inserted to shell history one by one.
COMMAND is either a plain string or a string of %-constructs.
%f -- print visited file name.
%s -- print short file name, with posfix removed

- For any files of *.erl, append two commands to related shell history
 (\"*.erl\" . ((\"make && ./start.sh\") (\"erlc ./%f && erl -noshell -s %s start_link\")))

- For any files whose filename match the regexp of bak, append one command to shell history
 (\"*.bak.*\" . ((\"rm -rf ./%f\")))

(defun load-shell-history(file-name)
  (let (shell-command shell-command-list)
    ;; add command list to shell historyp
    (make-local-variable 'comint-input-ring)
    (setq shell-command-list (assoc-default file-name shell-history-alist 'string-match))
    (if shell-command-list
          ;; reverse the list
          (setq shell-command-list (nreverse shell-command-list))
          (dolist (command shell-command-list)
            (setq shell-command (car command))
            ;; replace the %-construct with the runtime value
            (setq shell-command (replace-regexp-in-string "%f" file-name shell-command))
            (setq shell-command
                  (replace-regexp-in-string "%s" (file-name-sans-extension file-name) shell-command))
            (ring-insert-at-beginning comint-input-ring shell-command))
          (move-beginning-of-line nil)
(global-set-key [f9] 'open-related-shell)
;; f9.: only spawn one shell for files in the same directory
;; C-u f9.: shell is spawn by file, instead of by directory
(defun open-related-shell(&optional arg)
  "By default, if current file doesn't open a shell, generate one.
Otherwise, switch to related shell.

If arg is given, only open a shell for one direcotry.
  (interactive "P")
  (if (null arg) (open-shell-of-current-directory)

;; --8<-------------------------- §separator§ ------------------------>8--
;; When killing a file, also kill related shell buffer
(add-hook 'kill-buffer-hook 'kill-shell-buffer)
(defun kill-shell-buffer()
  "When killing a file, also kill related shell buffer."
  (let* ((file-name (buffer-name)) shell-buffer-name)
    (setq shell-buffer-name (concat "*shell*-" file-name))
    (if (get-buffer shell-buffer-name)
        (kill-buffer shell-buffer-name))
;; --8<-------------------------- §separator§ ------------------------>8--
(dolist (mode-hook-var '(shell-mode-hook eshell-mode-hook))
  (add-hook mode-hook-var
            '(lambda ()(local-set-key (kbd "C-l") 'clear-shell))))
(defun clear-shell ()
  "Remove content of shell/eshell, with the prompt lines reserved"
   ((string-equal mode-name "Shell")
    ;; In shell buffer, leverage comint
    (let ((comint-buffer-maximum-size 0))
   ((string-equal mode-name "EShell")
    ;; In eshell buffer, simply delete content of region
    (let ((inhibit-read-only t))
      (goto-char (point-min))
      (forward-line 2)
      (eval-after-load 'eshell
      (kill-region (point) (point-max))))
;; --8<-------------------------- §separator§ ------------------------>8--
(global-set-key (kbd "<C-f9>") 'eshell-toggle)
;; quickly switch to eshell, and do buffer toggle things
(load-file (concat CONTRIBUTOR_CONF "/eshell-toggle/eshell-toggle.el"))
(autoload 'eshell-toggle "eshell-toggle"
  "Toggles between the *eshell* buffer and whatever buffer you are editing."
(autoload 'eshell-toggle-cd "eshell-toggle"
  "Pops up a eshell-buffer and insert a \"cd <file-dir>\" command." t)
;; --8<-------------------------- §separator§ ------------------------>8--
(eval-after-load 'eshell
  (setq eshell-cmpl-cycle-completions nil
        eshell-save-history-on-exit t
        eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'"))
;; --8<-------------------------- §separator§ ------------------------>8--
;; set $PATH
(setq eshell-path-env (concat eshell-path-env ":/opt/local/bin"))
;; --8<-------------------------- §separator§ ------------------------>8--
(defun python-shell()
  "make a python shell"
  (switch-to-buffer (make-comint "python" "python" nil "-i")))
(defun perl-shell()
  "make a perl db shell"
  (switch-to-buffer (make-comint "perl" "perl" nil "-d -e''")))
;; --8<-------------------------- §separator§ ------------------------>8--
;; File: skill.org

5.4 Invoking Multiple Shells: Ctrl+u Alt+x shell, or (shell shell-buffer-name)

CLOSED: 2012-03-02 五 22:00
EmacsWiki: Shell Mode

Michael Tsai – Blog – Multiple Emacs Shell Buffers

5.5 eshell中定义alias    IMPORTANT

CLOSED: 2009-05-24 星期日 11:28
alias bankreg=’ledger -f filebat.ledger -M reg’
alias bankbal=”ledger -f filebat.ledger -d ‘T&l<4′ bal ”

5.6 clean eshell buffer

CLOSED: 2011-08-16 Tue 08:24
(put ‘erase-buffer ‘disabled nil)
(defalias ‘clear ‘erase-buffer)

5.7 useful link

A Complete Guide to Mastering Eshell | Mastering Emacs

6 EMMS in emacs

CLOSED: 2011-04-24 Sun 07:28

  • command list
Item Summary
+ emms-volume-raise
< emms-seek-backward
> emms-seek-forward
P emms-pause 暂停/继续
s emms-stop
E emms-tag-editor-edit 编辑mp3info
c emms-playlist-mode-center-current 跳到当前播放的这首歌中
r emms-random随机播放歌曲
  • sort song
Item Summary
S N emms-playlist-sort-by-name
S n emms-playlist-sort-by-natural-order
  • scoring
Item Summary
S D emms-score-down-playing 加分
S U emms-score-up-playing 减分
S d emms-score-down-file-on-line
S u emms-score-up-file-on-line
S s emms-score-show-playing 显示某首歌的分数
S l emms-score-less-tolerant只听分数小于某个设定值的歌
S m emms-score-less-tolerant只听分数大于某个设定值的歌
  • filter song
Item Summary
/ / emms-playlist-limit-to-all 显示所有歌曲
/ a emms-playlist-limit-to-info-artist 基于歌手名的regexp匹配
/ n emms-playlist-limit-to-info-artist 基于歌曲名的regexp匹配
/ g emms-playlist-limit-to-info-genre 基于歌曲类型的regexp匹配

歌曲mp3info一般含有如下信息, 示例:

name             = /home/denny/backup/multimediea/music/赵传--我是一只小小鸟.mp3
info-artist      = 赵传
info-composer    =
info-performer   =
info-title       = 我是一只小小鸟
info-album       = 精选
info-tracknumber = 0
info-year        = 0
info-genre       =
info-note        =

6.1 basic use

emms要调用音乐播放工具才能播放音乐,一般要安装mpg321;同时建议安装mp3info,以显示 mp3音乐文件的信息
sudo apt-get install imagemagick
sudo apt-get install emms
sudo apt-get install mplayer
sudo apt-get install mpg321

6.2 音乐: 快进以及回放

(define-key emms-playlist-mode-map (kbd "<right>") (lambda () (interactive) (emms-seek +10)))
(define-key emms-playlist-mode-map (kbd "<left>") (lambda () (interactive) (emms-seek -10)))
(define-key emms-playlist-mode-map (kbd "<up>") (lambda () (interactive) (emms-seek +60)))
(define-key emms-playlist-mode-map (kbd "<down>") (lambda () (interactive) (emms-seek -60)))

6.3 音乐打分: emms-score-hash

(require 'emms-score)
(emms-score 1)
(define-key emms-playlist-mode-map (kbd "S u") 'emms-score-up-file-on-line)
(define-key emms-playlist-mode-map (kbd "S d") 'emms-score-down-file-on-line)
(define-key emms-playlist-mode-map (kbd "S o") 'emms-score-show-file-on-line)
(define-key emms-playlist-mode-map (kbd "S l") 'emms-score-less-tolerant)
(define-key emms-playlist-mode-map (kbd "S m") 'emms-score-more-tolerant)
(define-key emms-playlist-mode-map (kbd "S t") 'emms-score-set-tolerance)
(define-key emms-playlist-mode-map (kbd "S s") 'emms-score-show-playing)
(define-key emms-playlist-mode-map (kbd "S U") 'emms-score-up-playing)
(define-key emms-playlist-mode-map (kbd "S D") 'emms-score-down-playing)

6.4 useful link

ubuntu emacs 听音乐 看电影 看图片
Emacs下的多媒体系统 – EMMS
EMMS–Emacs Multimedia System
The Emacs Multimedia System
TANSTAAFL — 使用emms来听音乐
EmacsWiki: init-emms.el

6.5 sort emms playlist by decrease play count    IMPORTANT

CLOSED: 2012-04-17 二 00:02

;; sort emms playlist by decrease play count
(setq emms-playlist-sort-function '(lambda ()
                                     (let ((current-prefix-arg t))
(defadvice emms (after emms-playlist-mode-go activate)

6.6 emms 显示歌词

CLOSED: 2012-04-10 二 00:58
emms-lyrics-visit-lyric: Visit playing track’s lyric file.

(require 'emms-lyrics)
(setq emms-lyrics-dir emms-source-file-default-directory)

6.6.1 OSD Lyrics: 受lrcdis的启发而开发的一款第三方歌词显示程序。

6.7 emms jump to current directory quickly

CLOSED: 2012-04-10 二 23:51

;; set default-directory correctly, for checking media files easily in emms playlist buffer
(add-hook 'emms-playlist-mode-hook
          '(lambda() (setq default-directory emms-source-file-default-directory)))

7 Dired mode in emacs

Name Summary
refresh dired window g
use dired to copy files C
use dired to untar package T(dired-tar-pack-unpack)
use dired to remove a folder D
use dired to move a folder R
kill all marked lines k

7.1 useful commands in dired

Type * / dired-mark-directories
Type * ? dired-unmark-all-files
Type * t dired-toggle-marks
Type * s dired-mark-subdir-files
Type 【t k】 display only the marked files by using the command
Type 【k】 kills (that is, hides) all the marked files.
Type 【g】 restore things with the
Type o to find file or dired directory in Other window.
Type C to Copy files.
Type R to Rename a file or move the marked files to another directory.
Type m to Mark a file or subdirectory for later commands.
Type u to Unmark a file or all files of a subdirectory.
Instead, type d to flag a file for Deletion.
Type x to execute the deletions requested.
Type s to toggle Sorting by name/date or change the `ls' switches.
Type g to read all currently expanded directories aGain.

7.2 s(dired-sort-toggle-or-edit): toggle Sorting by name/date or change the `ls’ switches.

CLOSED: 2011-03-02 Wed 14:38

7.3 move to parent directory in dired mode: dired-up-directory(^)

CLOSED: 2010-03-21 星期日 17:16

7.4 在dired中,一次性选择*.mxml和*.as两类文件: find-dired -> -iname “*.el” -or -iname “*.html”    IMPORTANT

CLOSED: 2010-03-21 星期日 17:14

7.5 dired mode中设置为只打开一个buffer

CLOSED: 2009-05-24 星期日 14:22
In Emacs 22, you can use ‘a’ in a Dired buffer, instead of ‘e’, ‘f’, and ‘RET’.
(put ‘dired-find-alternate-file ‘disabled nil)

7.6 find-name-dired: exclude the direcotry of .svn    IMPORTANT

(setq find-ls-option ‘(“-exec ls -ld \”{}\” \”;\” | grep -v ./.svn” . “-ld”))

7.7 dired-mode中,对选中的多个文件重命名, 名字前加前缀: % r -> \(.*\) -> pre_\1    IMPORTANT

CLOSED: 2010-03-27 星期六 13:43
% r dired-do-rename-regexp
% u dired-upcase
% l dired-downcase

7.7.1 dired中, 调用convert将*.jpg文件批量转化为*.png

CLOSED: 2011-07-24 Sun 15:04

7.8 在dired-mode中按正则表达式规则选中一组文件: dired-mark-files-regexp

CLOSED: 2010-03-27 星期六 01:41
% m dired-mark-files-regexp
% g dired-mark-files-containing-regexp

7.9 shortkey to handle marks in dired mode

CLOSED: 2010-03-27 星期六 01:46
“U dired-unmark-all-marks”
“t dired-toggle-marks”
“* C-n dired-next-marked-file”
“* C-p dired-prev-marked-file”

7.10 Dired-mode: sort files by size    IMPORTANT

CLOSED: 2011-03-02 Wed 15:21
C-u s:之后修改parameter为-alS。由小到大的话,改为-alSr
emacs – Cutomizing dired – Stack Overflow

7.11 dired-mode中,快速地以OS的资源管理程序的方式打开文件夹

CLOSED: 2011-04-24 Sun 13:05

(defun open-folder-in-explorer ()
"Call when editing a file in a buffer. Open windows explorer in the current directory and select the current file"
"open" "explorer"
(concat "/e,/select," (convert-standard-filename buffer-file-name))
(global-set-key [(control x)(control d)] 'open-folder-in-explorer)
(defun open-folder-in-explorer ()
"Call when editing a file in a buffer. Open windows explorer in the current directory"
(shell-command-to-string (concat "nautilus --browser " default-directory))
(global-set-key [(control x)(control d)] 'open-folder-in-explorer)

7.11.1 useful link

7.12 list all matched strings in marked files of dired    IMPORTANT

CLOSED: 2011-07-24 Sun 15:05
;; ————————– separator ————————–

  • color-moccur: dired-do-moccur
  • dired+: diredp-do-grep
  • dired-do-search

7.13 dired: 显示文件大小时, 使用MB, KB的方式

CLOSED: 2011-09-16 Fri 18:02
(setq dired-listing-switches “-alhS”)

7.14 dired对选中的所有文件, 运行基于文件名的命令

CLOSED: 2011-10-20 Thu 16:57

7.15 dired-flag-backup-files(): Flag all backup files (names ending with `‘) for deletion.

CLOSED: 2011-08-14 Sun 14:59

7.16 批量删除一个文件夹中, 所有文件的tailing space: M-x find-name-dired + t + Q

CLOSED: 2009-08-31 星期一 23:10

7.17 通过dired的模式,先选中一组文件,再M-x dired-do-query-replace-regexp

CLOSED: 2009-07-22 星期三 00:07

  1. M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
  2. Press t to “toggle mark” for all files found.
  3. Press Q for “Query-Replace in Files…”: you will be prompted for query/substitution regexps.
  4. Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.

7.18 emacs支持回收站

CLOSED: 2011-10-26 Wed 21:38
(setq delete-by-moving-to-trash t) ;; When deletion in emacs, uses system’s trash
(setq trash-directory “~/trash”)

8 Search/Replace in emacs

8.2 emacs regexp search with prefix customized

CLOSED: 2012-04-18 Wed 10:12

(defun add-isearch-regexp-prefix (search-prefix)
  "Add regexp prefix for regexp searching."
    (delete search-prefix regexp-search-ring)
    (setq regexp-search-ring (add-to-list 'regexp-search-ring search-prefix))
    (message "regexp search with prefix: %s" search-prefix)
(defun search-function ()
  "Searching functions for various programming mode."
  (let ((mode-prefix '(("Python" . "^ *def")
                       ("Erlang" . "^[a-zA-Z]")
                       ("C++/l" . "^[a-zA-Z]")
                       ("Emacs-Lisp" . "^(defun ")
                       ("Lisp" . "^(defun ")
                       ("Shell" . "^function "))))
    (add-isearch-regexp-prefix (assoc-default mode-name mode-prefix))
(global-set-key (kbd "C-c C-f") 'search-function)
(define-key python-mode-map (kbd "C-c C-f") 'search-function)

8.3 匹配出现的次数:(string-match “^\\*\\{1,2\\} .*” x)

CLOSED: 2012-01-20 Fri 19:46

(setq x "** 心态")
(string-match "^\\*\\{1,2\\} .*" x)

8.4 反向引用:将<operation:Component开头, 以>结尾的行中间插入name=”tt”

CLOSED: 2009-05-10 星期日 15:07
<operation:OperationComponent\1 name=”t”>)
In an Emacs regexp, “(” and “)” match actual parens, while “\(” and “\)” create matching groups.
替换:”^= \(Preface\) =$”->”= before\1after =”

8.5 M-x re-builder:显示正则表达式效果

CLOSED: 2009-05-10 星期日 15:09

8.6 在增量搜索中,要用 <TAB> 输入制表符,”C-j”输入换行符

CLOSED: 2009-05-10 星期日 15:09

8.7 如何输入一个回车:C-q C-j    IMPORTANT

CLOSED: 2009-05-09 星期六 16:43
Ctrl-q is Emacs’s “quote” command: rather than executing the following keystroke, Emacs will insert the key into the current buffer or the minibuffer.
effective emacs

8.7.1 对于行为public function setDefaultData(defaultData:Object):void{, 加多一行if(defaultData == null) return;

CLOSED: 2009-05-10 星期日 14:49
setDefaultData(defaultData:Object):void{$, C-q, C-j, if(defaultData == null) return;

8.8 满足一定条件的行,将其删除,而非设置为空行    RECOMMENDATE

CLOSED: 2009-05-10 星期日 14:40

8.8.1 修改默认的flush-lines函数

(defun query-flush-lines (regexp &optional rstart rend interactive)
(keep-lines-read-args "Flush lines (containing match for regexp): ")))
(if rstart
(goto-char (min rstart rend))
(setq rend (copy-marker (max rstart rend))))
(if (and interactive transient-mark-mode mark-active)
(setq rstart (region-beginning)
rend (copy-marker (region-end)))
(setq rstart (point)
rend (point-max-marker)))
(goto-char rstart))
(let ((case-fold-search (and case-fold-search
(isearch-no-upper-case-p regexp t))))
(while (and (< (point) rend)
(re-search-forward regexp rend t))
(if (y-or-n-p "Flush? ")
(delete-region (save-excursion (goto-char (match-beginning 0))
(forward-line 0)
(progn (forward-line 1) (point))))))))
(set-marker rend nil)

8.9 query-replace-regexp中, 匹配”None): 先按C-q,再输入)

CLOSED: 2009-05-09 星期六 16:45

8.10 将开头的四个空格改成一个tab键

CLOSED: 2009-04-22 Wed 22:57
M-x query-replace-regexp “^ ” ” “(后面是tab键)

8.11 将(setq开头, 含有default字符串的行替换成空行

CLOSED: 2009-04-22 Wed 23:22
M-x query-replace-regexp “^<Operation:Component.*default.*$” “”
.是emacs正则表达式的特殊字符, 匹配除了换行符(newline)之外任何单个字符的特殊字符

8.12 去掉行首的空格

CLOSED: 2009-04-22 Wed 22:55
M-x query-replace-regexp “^ +” “”

8.13 Add one to a number using Emacs’ regexp    IMPORTANT Difficult

CLOSED: 2011-01-11 Tue 14:20

Add one to a number using Emacs&#8217; regexp
"\,(1+ \#1)"
;; -------------------------- separator --------------------------
I recently had to add one to all numbers of the form "n" where n is a number in a text file.
Thanks to jlf on #emacs, I could do so with the
command replace-regexp to change \"\([0-9]+\)\" to "\,(1+ \#1)".
I’m never going to remember this so I’m writing it down now.

8.14 搜索tab键:C-s C-i

CLOSED: 2009-05-03 星期日 23:13

8.15 search content of current word: C-w

CLOSED: 2010-03-21 星期日 18:56

8.16 search content of current line: C-y

CLOSED: 2010-03-21 星期日 18:55

8.17 search recursively: M-x rgrep

CLOSED: 2009-07-21 星期二 23:54

8.18 只在el后缀名的文件中使用grep-find:rgrep    IMPORTANT

CLOSED: 2010-03-21 星期日 18:13

8.19 修改query-flush-lines:查询删除行print “\n”

CLOSED: 2010-02-10 星期三 22:20

8.20 查找替换:在每行后加一个空行, C-q C-j(输入一个回车)

CLOSED: 2010-03-29 星期一 15:41
map.resources :users
map.resources :depts
map.resources :employees
map.resources :purchases
map.resources :suppliers
map.resources :inbounds
map.resources :depots
map.resources :products
map.resources :outbounds
map.resources :sales
map.resources :saledetails
map.resources :transportations
map.resources :ycustomers

8.21 Replacement text can depend on found text    IMPORTANT HARD

CLOSED: 2010-03-27 星期六 19:52

Item Meaning
\& the matched string
\1, \2, etc references to parts of matched string
\# number of lines matched so far
\? prompt user and insert entered text
\,(…) arbitrary lisp expression

Replace “Bill Gates” to “Gates, Bill”: \(\w+\) \(\w+\) -> \,(upcase \2), \1

8.22 perform interactive regexp search -> isearch-forward-regexp

CLOSED: 2010-04-22 星期四 22:47

8.23 search current word: C-s C-w

CLOSED: 2010-04-22 星期四 23:12

8.24 grep时给出相差两行: setq list-matching-lines-default-context-lines 3

CLOSED: 2010-07-31 星期六 10:44
(defun occur-context (regexp &optional nlines)
(interactive (occur-read-primary-args))
(let ((list-matching-lines-default-context-lines 1))
(occur-1 regexp nlines (list (current-buffer))))

8.25 emacs将超过两行的空行转成一行:C-Q C-J\{3,\} –>C-Q C-J

CLOSED: 2011-03-17 Thu 10:46
delete-blank-lines bound to C-x C-o.
Removing blank lines in a buffer | Mastering Emacs

8.26 emacs中输^M: C-q C-m

CLOSED: 2011-07-08 Fri 10:36

8.27 搜索不含有 call: snmp_sys_uptime的行: grep -v “call: snmp_sys_uptime” mauiutility.py

CLOSED: 2010-04-04 星期日 22:51

8.28 sample

CLOSED: 2011-10-20 Thu 22:51

正则表达式中, C-o表示空?
Open dot files listed in buffer Regexp : \<\.\w+
Replace: \,(find-file-noselect \&)
Capitalize char beginning line Regexp : ^.
Replace: \,(capitalize \&)
Convert dd/mm/ to mm-dd- Regexp : \(<0-9><0-9>\)/\(<0-9><0-9>\)/
Replace: \2-\1-
Keep only number at end of line Regexp : ^.*[^0-9 C-q C-j ]
Permute foo and bar Regexp : \(foo\)\|bar
Replace: \,(if \1 "bar" "foo")
Remove DOS style newlines Regexp : C-q 015 RET
Regexp :
Number chapter Regexp : \(chapter \)
Replace: \1 \,(1+ \#)
Add 1 to number starting line Regexp : ^<0-9>+
Replace: \,(1+ \#&)
Kill buffer if contains "yop" Regexp : yop
Replace: \,(progn (kill-buffer nil) \&)
Count words Regexp : \<

9 yas: template input

yasnippet-bundle is much better than emacs default abbreviation:
- Instead of blindly replacing, we may want some parts to be intelligently updated
  In below example, many parts are updated by tiny elisp functions.



- Moving in skeleton
  The replacement may need to be updated manually.
  Further more, there may be more than one change, thus we need quick jump.
  In below example, we can jump from $1 to $2, by pressing tab


10 Denny’s lisp

10.1 compare two lines 2010-05-21 15:17 UTC +8    IMPORTANT

CLOSED: 2010-05-22 星期六 23:18


10.1.1 code

(defun compare-sequent-lines ()
 "Compare two sequent lines in the same buffer, by calling ediff-regions-internal"
 (move-beginning-of-line 1)
 (setq beg-a (point))
 (move-end-of-line 1)
 (setq end-a (point))
 (next-line 1)
 (move-beginning-of-line 1)
 (setq beg-b (point))
 (move-end-of-line 1)
 (setq end-b (point))
 (get-buffer (buffer-name)) beg-a end-a
 (get-buffer (buffer-name)) beg-b end-b
 nil 'ediff-windows-wordwise 'word-mode nil)

10.1.2 mail from gnu maillist

Hi all
Can we compare two sequent lines in one file? A sample file can be found at the bottom.
With my friend's suggestion, I have managed to do this by calling an internal function(ediff-regions-internal) of ediff.el.
However, leveraging internal interface is quite dangerous.
Besides, this is still some more effort to make it work with the way of ediff-regions-internal.
I may even have to change the code of ediff.el!
I am referring to my super heroes in the mail list. Can anyone give me a hint for a better way?
| ========= Difference =========
| MDLS_List=dailybuild1-171-112-r1s1-002,dailybuild1-171-112-r1s1-001,dailybuild1-171-112-r2s1-002,dailybuild1-171-112-r2s1-001
| MDLS_List=dailybuild1-171-112-r1s1-001,dailybuild1-171-112-r1s1-003,dailybuild1-171-112-r2s1-002,dailybuild1-171-112-r2s1-001
| ========= Difference =========
| SS_DiskList=/dev/sdd1,/dev/sdd2,/dev/sde1,/dev/sde1
| SS_DiskList=/dev/sdc1,/dev/sdd1,/dev/sde1,/dev/sdf1
| ========= Difference =========
| SS_NumDisks=2
| SS_NumDisks=4

10.2 Show how many matched counts for grep-find    IMPORTANT

CLOSED: 2010-06-28 星期一 23:58

(defadvice grep-find (after show-grep())
 (set-buffer "*grep*")
 (sleep-for SLEEP_INTERVAL)
 "%d matches found"
 (- (count-lines (point-min) (point-max)) 6))
(ad-activate 'grep-find)

Advising Emacs Lisp Functions

10.2.1 mail

When grep-find, show the count of matches
Hi emacsers
I am wondering that how to show the count of matches when grep-find. Like the following.
| -*- mode: grep; default-directory: "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
| Grep started at Mon Jun 28 17:46:18
| find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep -inH -e emacs
| ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) IMPORTANT(i) HARD(h) Communication(c) RECOMMENDATE(r) Tool(t)
| ./#tmp.txt#:47438:* TODO log4j-mode in emacs
| ./#tmp.txt#:47529:Hi emacsers
| ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i in emacs 23</p>
| ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i in emacs 23</p>
| ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) IMPORTANT(i) HARD(h) Communication(c) RECOMMENDATE(r) Tool(t)
| ./tmp.txt:47438:* TODO log4j-mode in emacs
| Grep finished (7 matches found) at Mon Jun 28 17:46:20
IMHO, one feasible way may be count the output of *grep* buffer.
I am very willing to hear your ideas, comment or codesnipet for this?

10.3 get title of web page by url

 CLOSED: [2010-07-31 星期六 10:47]
#+begin_src elisp
;;alt+p t: get title of web page, whose url can be found in the current line.
(global-set-key [(meta p)(t)] 'get-page-title)
(defun get-page-title()
  "Get title of web page, whose url can be found in the current line"
    (let (url point-start point-end line-str web_title_str coding_charset)
      ;; Get url from current line
      (move-beginning-of-line nil)
      (setq point-start (point))
      (move-end-of-line nil)
      (setq point-end (point))
      (setq line-str (buffer-substring-no-properties point-start point-end))
      ;; search by regexp
      (if (string-match "\\(https\\{0,1\\}://[^ ]+\\)" line-str)
          (setq url (substring line-str (match-beginning 0) (match-end 1))))
      ;; Get title of web page, with the help of functions in url.el
      (with-current-buffer (url-retrieve-synchronously url)
        ;; find title by grep the html code
        (goto-char 0)
        (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
        (setq web_title_str (match-string 1))
        ;; find charset by grep the html code
        (goto-char 0)
        (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
        ;; downcase the charaset. e.g, UTF-8 is not acceptible for emacs, while utf-8 is ok.
        (setq coding_charset (downcase (match-string 1)))
        ;; decode the string of title.
        (setq web_title_str (decode-coding-string web_title_str (intern coding_charset))))
      ;; Insert the title in the next line
      (insert web_title_str)))

10.4 emacs查看网页的源代码

CLOSED: 2011-06-21 Tue 08:15

(url-retrieve-synchronously "http://localhost/metinfo/product/?action=search")

(global-set-key [(meta p)(h)] 'get-page-html-source)
(defun get-page-html-source()
"Get html source of web page, whose url can be found in the current line"
;; Get url from current line
(copy-region-as-kill (re-search-backward "^") (re-search-forward "$"))
(setq url (substring-no-properties (current-kill 0)))
;; remove heading spaces
(setq url (replace-regexp-in-string "^ +" "" url))
(setq html_file "~/html_source.html")
;; Get title of web page, with the help of functions in url.el
(with-current-buffer (url-retrieve-synchronously url)
(write-file html_file)
;; convert charset
(get-file-buffer html_file)
(set-buffer-file-coding-system 'utf-8)
(kill-buffer (get-file-buffer html_file))
;; open file and bring to the front
(find-file html_file)
(goto-char 0)

10.5 grep时给出相差两行: setq list-matching-lines-default-context-lines 3

CLOSED: 2010-07-31 星期六 10:44

(defun occur-context (regexp &optional nlines)
(interactive (occur-read-primary-args))
(let ((list-matching-lines-default-context-lines 1))
(occur-1 regexp nlines (list (current-buffer))))

10.6 online-search.el

CLOSED: 2011-07-08 Fri 09:42

10.7 emacs: auto update for current file name    IMPORTANT

CLOSED: 2011-09-11 Sun 10:54

(add-hook 'write-file-hooks 'auto-update-file-fields)
(defun auto-update-file-fields ()
 "Update fields in file, such as filename, time-stamp, etc
 - filename format:
 # File : skill.org
 (let ((file-name-regexp "\\(File \\: \\)\\(.*\\)"))
 (goto-char (point-min))
 ;; Verify looking at a file name for this mode.
 (while (re-search-forward file-name-regexp nil t)
 (goto-char (match-beginning 2))
 (delete-region (match-beginning 2) (match-end 2))
 (insert (file-name-nondirectory (buffer-file-name)))

10.8 emacs: define shortcut to switch to another window: Ctrl + return

CLOSED: 2011-09-11 Sun 09:58

(global-set-key (kbd "<C-return>") 'switch-to-next-buffer)
(defun switch-to-next-buffer ()
 "Switch to next buffer, with certain buffer excluded from the candidates"
 (let* (buffer-choose-list
 (buffer-prohibit-list '())
 (buffer-prohibit-regexp-list '(".*Minibuf.*" "\*shell\*.*"
 ".*\*Backtrace\*" ".*\*Messages\*.*"
 ;; filter current buffer out
 (setq buffer-choose-list (cdr (buffer-list)))
 ;; if one buffer's name matchs buffer-prohibit-regexp-list, add it to buffer-prohibit-list
 (dolist (buffer-var buffer-choose-list)
 (dolist (buffer-prohibit-regexp buffer-prohibit-regexp-list)
 (if (string-match buffer-prohibit-regexp (buffer-name buffer-var))
 (add-to-list 'buffer-prohibit-list buffer-var)
 ;; remove all buffers in buffer-prohibit-list from buffer-choose-list
 (dolist (buffer-var buffer-prohibit-list)
 (setq buffer-choose-list (delq buffer-var buffer-choose-list)))
 ;; switch to next proper buffer
 (switch-to-buffer (car buffer-choose-list))

10.9 emacs定义flush-word

CLOSED: 2011-10-01 Sat 22:19

(thing-at-point 'word)

(defun flush-words (regexp &optional rstart rend interactive)
  "Delete words containing matches for REGEXP.

If REGEXP contains upper case characters (excluding those preceded by `\\')
and `search-upper-case' is non-nil, the matching is case-sensitive.

Second and third arg RSTART and REND specify the region to operate on.
Lines partially contained in this region are deleted if and only if
they contain a match entirely contained in it.

Interactively, in Transient Mark mode when the mark is active, operate
on the contents of the region. Otherwise, operate from point to the
end of (the accessible portion of) the buffer. When calling this function
from Lisp, you can pretend that it was called interactively by passing
a non-nil INTERACTIVE argument.

If a match is split across lines, all the lines it lies in are deleted.
They are deleted _before_ looking for the next match. Hence, a match
starting on the same line at which another match ended is ignored."

     ;; (keep-lines-read-args "Flush words containing match for regexp")))
     (list (read-regexp "Flush words containing match for regexp"
                        (thing-at-point 'word)) nil nil t)))
  (if rstart
        (goto-char (min rstart rend))
        (setq rend (copy-marker (max rstart rend))))
    (if (and interactive transient-mark-mode mark-active)
        (setq rstart (region-beginning)
              rend (copy-marker (region-end)))
      (setq rstart (point)
            rend (point-max-marker)))
    (goto-char rstart))
  (replace-regexp regexp "" nil rstart rend)

10.10 emacs格式化代码或文本

CLOSED: 2011-10-26 Wed 14:31

(defun clean-up-buffer-or-region (cleanup-replace-rule-list)
  "Clean up buffer or region by following:
 Untabifies, indents and deletes trailing whitespace from buffer or region,
 And make necessary replacement, according to the lsit of cleanup-replace-rule-list"
    ;; clean useless characters based on rule list
    (dolist (replace-rule cleanup-replace-rule-list)
      (goto-char (point-min))
      (while (re-search-forward (nth 0 replace-rule) nil t)
        (replace-match (nth 1 replace-rule) t))
  ;; untabify, indent-region, etc
  (unless (region-active-p) (mark-whole-buffer))
  (unless (member mode-name '("Org"))
    (untabify (region-beginning) (region-end))
    (indent-region (region-beginning) (region-end)))
  (narrow-to-region (region-beginning) (region-end))
(global-set-key (kbd "C-c c") 'beautify-region-by-mode)
(defun beautify-region-by-mode()
    (let (cleanup-replace-rule-list)
       ((string-equal mode-name "Org")
        (setq cleanup-replace-rule-list
              '(("\n\n+\\\*" "\n*")
        (setq cleanup-replace-rule-list
              '(("\n\n+" "\n\n")
                (" +" " ")
                ("\\([^=: !+/-]\\)=" "\\1 =") ;; insert space in the left of equation, if ncessary
                ("=\\([^=: !+/-]\\)" "= \\1") ;; insert space in the right of equation, if ncessary
      (clean-up-buffer-or-region cleanup-replace-rule-list)

10.11 # –8<————————– §separator§ ————————>8–

10.12 emacs: show interesting information for current file or directory

CLOSED: 2011-10-26 Wed 14:32

;;M-p i: show interesting information for current file or directory
;;C-u M-p i: show short file name of current buffer
(define-key global-map (kbd "M-p i") 'show-magic-info)
(defun show-magic-info(show-short-info-p)
  "show interesting information for current file or directory
 - If current position is dired, show lines counts for misc programming lanuages.
 - If current position is a file, show file name and line counts
 - If current position is in *w3m*, show current web title
 - If current positioin is in Article mail mode, show the url under current cursor
 If show-short-info-p is not null, the default behaviour is showing short filename of current buffer
  (interactive "P")
  (let ((output_str buffer-file-name))
    (if (and output_str show-short-info-p) (setq output_str (file-name-nondirectory output_str)))
     ((string-equal mode-name "w3m") (setq output_str (w3m-current-title)))
     ((string-match "Dired" mode-name)
      (setq output_str (count-code-lines-in-directory default-directory)))
     ((string-equal mode-name "Article") (setq output_str (w3m-print-this-url)))
    (when output_str
      ;; display the result
      (message output_str)
      ;; send the result to kill-string
      (kill-new output_str))
(defun count-code-lines-in-directory(directory &optional lanuage-postfix-list)
  " Count code lines for various programming lanuages, with the help of below utility:
 find . -name '%s' | xargs wc -l 2>/dev/null | tail -n 1
  (interactive "Ddirectory:")
  (let (command-output (output-str "Count code lines."))
    ;; set lanuages to be checked, if not given
    (if (null lanuage-postfix-list)
        (setq lanuage-postfix-list '("*.php" "*.c" "*.c++" "*.cxx" "*.rb" "*.py"
                                     "*.el" "*.sh" "*.java" "*.pl" "*.erl" "*.cpp"
                                     "*.js" "*.sql" "*.mxml" "*.as")))
    ;; count lines
    (dolist (lanuage-var lanuage-postfix-list)
      ;; TODO, remove comments from counting
      ;; suppress the possible stderr for wc, since some temporary files may not be reachable.
      (setq command-output (shell-command-to-string
                            (format "find . -name '%s' | xargs wc -l 2>/dev/null | tail -n 1" lanuage-var)))
      (unless (string= command-output "0\n")
        (setq output-str (format "%s\n%s: %s " output-str lanuage-var command-output))
    ;; return the result
    (eval output-str)

10.13 emacs: Switch to next buffer in the same mode

CLOSED: 2011-10-23 Sun 20:12

(global-set-key (kbd "<C-return>") 'switch-to-mode-nex-buffer)
(defun switch-to-mode-nex-buffer()
  "Switch to next buffer in the same mode, and also with certain buffer excluded from the candidates"
  (let* ((old-buffer-mode mode-name)
         (buffer-prohibit-list '())
         (buffer-prohibit-regexp-list '(".*Minibuf.*" "\*shell\*.*"
                                        ".*\*Backtrace\*" ".*\*Messages\*.*"
    ;; filter current buffer out
    (setq buffer-choose-list (cdr (buffer-list)))
    ;; if one buffer's name matchs buffer-prohibit-regexp-list, add it to buffer-prohibit-list
    (dolist (buffer-var buffer-choose-list)
      (set-buffer buffer-var)
      (if (string= old-buffer-mode mode-name)
          ;; If buffer is in the same mode with current buffer, check whether we need further filter
          (dolist (buffer-prohibit-regexp buffer-prohibit-regexp-list)
            (if (string-match buffer-prohibit-regexp (buffer-name buffer-var))
                (add-to-list 'buffer-prohibit-list buffer-var)
        ;; filter buffers which have a different mode
        (add-to-list 'buffer-prohibit-list buffer-var)
    ;; remove all buffers in buffer-prohibit-list from buffer-choose-list
    (dolist (buffer-var buffer-prohibit-list)
      (setq buffer-choose-list (delq buffer-var buffer-choose-list)))
    ;; switch to next proper buffer
    (switch-to-buffer (car buffer-choose-list))

10.14 emacs: regexp search in org-mode title

CLOSED: 2011-10-23 Sun 20:14

(org-defkey org-mode-map [(meta .)] 'occur-org-title)
(defun occur-org-title()
  "when regexp search, only search title of org-mode entries"
  (let (regexp)
    (setq regexp (read-string "Search org entries whose title matching regexp: " "^\\\*+ .*"))
    (occur-1 regexp 0 (list (current-buffer)))))

10.15 emacs: grep-find with current word as the default search key

CLOSED: 2011-10-23 Sun 20:15

(global-set-key (kbd "C-.") 'grep-find-with-querystring-quoted)
;; C-u C-.: grep-find with current word as the default search key
(defun grep-find-with-querystring-quoted (obtain-current-word)
  "Enhance grep-find by the following points
 - auto quoting query string
 - preventing show the lengthy grep-find-command in minibuffer
 - set the word at cursor as the default search keyword"
  (interactive "P")
  (let (command-args search-keyword (initial-conent nil) (bounds (bounds-of-thing-at-point 'word)))
    (if (and obtain-current-word bounds)
        (setq initial-conent (buffer-substring-no-properties (car bounds) (cdr bounds))))
    (setq search-keyword (read-shell-command "Run find in current directory: "
                                             initial-conent 'grep-find-history))
    ;; ;; escape \" in the search keyword
    (setq search-keyword (replace-regexp-in-string "\\\"" "\\\\\"" search-keyword))
    ;; quote search-keyword with ""
    (setq command-args (concat grep-find-command "\"" search-keyword "\""))
    (grep command-args)))

10.16 emacs: combo search in BBDB buffer

CLOSED: 2011-10-23 Sun 20:17

(defun bbdb-combo (string elidep)
  "combo search in *BBDB* buffer"
  ;; TODO, implement in a better way without duplicate codes
   (list (bbdb-search-prompt "Search records %m regexp: ")
  (bbdb string elidep 't)

10.17 emacs gnus: send template mail

    CLOSED: [2011-10-23 Sun 20:39]
#+begin_src elisp
(defun send-template-mail()
  "Parse current buffer as a mail template, then send mails by send-groupmail-by-mailbuffer.
We consider {name} string as a variable, which will be replaced by the actual name"
    (goto-char (point-min))
    (let (start-point end-point string-temp
                      (to-marker "To: ") (subject-marker "Subject: ")
                      (from-marker "From: ") (content-marker "--text follows this line--")
                      marker (name-mail-list '()) subject mail-content from-mail)
      ;; set default the marker for name replacement
      (setq marker "{name}")
      ;; obtain name and mail address list of recipients by searching: XXX <>
      (search-forward to-marker nil t)
      (setq start-point (point))
      (search-forward subject-marker nil t)
      (backward-char (length subject-marker))
      (setq end-point (point))
      (setq string-temp (buffer-substring-no-properties start-point end-point))
      (setq name-mail-list
            (mapcar (lambda (x)
                      (list (let ((name x))
                              (bbdb-string-trim (replace-regexp-in-string "<\.*>" "" name)))
                            (let ((net x))
                              (bbdb-string-trim (replace-regexp-in-string ">" "" (replace-regexp-in-string "\.*<" "" net))))))
                    (split-string string-temp ",")))
      ;; Obtain subject by searching: Subject: XXX
      (setq start-point (+ end-point (length subject-marker)))
      (search-forward from-marker nil t)
      (backward-char (length from-marker))
      (setq end-point (point))
      (setq subject (buffer-substring-no-properties start-point end-point))
      ;; Obtain from by searching: From: XXX
      (setq start-point (+ end-point (length from-marker)))
      (search-forward content-marker nil t)
      (backward-char (length content-marker))
      (setq end-point (point))
      (setq from-mail (buffer-substring-no-properties start-point end-point))
      ;; Obtain mail content by searching: --text follows this line--
      (setq start-point (+ end-point (length content-marker)))
      (setq end-point (point-max))
      (setq mail-content (buffer-substring-no-properties start-point end-point))
      ;; send mails based on template
      (send-groupmail-by-template name-mail-list subject mail-content from-mail marker)

(defun send-groupmail-by-template (name-mail-list subject mail-content from-mail marker)
  "send group mails based on template.
 We send mails to each recipient a mail with subject and
 content specified by the variables of subject and mail-content.

 Before sending mails, we replace the marker in mail-content by the recipient's name.

 name-mail-list containing names should be a list of two-element lists,
 in the format (\"Name\" \"email address\").
  (dolist (name-mail-entry name-mail-list)
    (compose-mail (nth 1 name-mail-entry) ;; to address
                  `(("From" . ,from-mail)) ;; all other headers
                  nil nil nil nil) ;; don't remember
    (insert mail-content)
    ;; insert name
    (perform-replace marker (nth 0 name-mail-entry) nil nil nil)
#+end_src** Interoperation with others in emacs

10.18 emacs save screenshot

CLOSED: 2011-07-19 Tue 22:29

通过cli tool: scrot – capture a screenshot using imlib2

(defun save-screenshots (name)
 "Save shot full-screen.
To use this function, you need install scrot."
 (interactive "sPicture Name: ")
 (setq my-screenshots-storage-directory "~/")
 (setq shell-command-var (format "scrot %s%s.png" my-screenshots-storage-directory name))
 (shell-command shell-command-var)
 (message "Run command: %s" shell-command-var)

10.19 emacs top-mode: run the Unix program “top” from Emacs

CLOSED: 2011-07-20 Wed 10:30

  • 通过top查看进程
  • 杀死某个进程
  • 进程做高亮标注
  • 过滤某个用户进程

;; § ————————– separator ————————–
(define-key top-mode-map “n” ‘top-mode-next-line)
(define-key top-mode-map “p” ‘top-mode-previous-line)
(define-key top-mode-map “g” ‘top)
(define-key top-mode-map “q” ‘quit-window)
(define-key top-mode-map “k” ‘top-mode-kill)
(define-key top-mode-map “K” ‘top-mode-kill-noconfirm)
(define-key top-mode-map “s” ‘top-mode-strace)
(define-key top-mode-map “S” ‘top-mode-strace-noconfirm)
(define-key top-mode-map “r” ‘top-mode-renice)
(define-key top-mode-map “R” ‘top-mode-renice-noconfirm)
(define-key top-mode-map “m” ‘top-mode-mark)
(define-key top-mode-map “u” ‘top-mode-unmark)
(define-key top-mode-map “U” ‘top-mode-show-specific-user))

10.19.1 useful link

10.20 proced.el — operate on system processes like dired

CLOSED: 2011-10-04 Tue 22:13
M-x proced
f(`proced-filter’) specifies which system processes are displayed.
F(`proced-format’) specifies which attributes are displayed for each process.
Type s S or click on a header in the header line to change the sort scheme.
Type T to toggle whether the listing is displayed as process tree.

10.21 emacs df-mode: Minor mode to show space left on devices in the mode line

CLOSED: 2011-08-05 五 00:26
EmacsWiki: Df Mode

10.21.1 CANCELED 修改df-mode, 只在modeline中显示文件大小, 而不需要显示所有空闲空间大小: proced-mode可以解决问题

CLOSED: 2011-10-20 Thu 17:00

10.22 D-bus in emacs

D-bus : a simple way for applications to talk to one another

10.22.1 basic use

D-Bus is an IPC system used on Linux/Unix to communicate between applications
The communication is connection oriented to two kinds of message buses: a so called "system bus", and a "session bus".
All methods and signals an object supports are called "interface" of the object.

10.22.2 通过D-bus, 在emacs中调用外部程序tomboy的示例    IMPORTANT


  • CreateNamedNote
  • SetNoteContents
  • ListAllNotes
  • GetNoteTitle
  • FindNote
  • GetNoteContents

(require 'dbus)

(defun djcb-call-tomboy (method &rest args)
 "call the tomboy method METHOD with ARGS over dbus"
 (apply 'dbus-call-method
 :session ; use the session (not system) bus
 "org.gnome.Tomboy" ; service name
 "/org/gnome/Tomboy/RemoteControl" ; path name
 "org.gnome.Tomboy.RemoteControl" ; interface name
 method args))

(defun djcb-tomboy-create-note-region (b e name)
 "Create a new note with in the Tomboy notetaker from region"
 (interactive "r\nsName for new Tomboy note:")
 (let ((note-uri (djcb-call-tomboy "CreateNamedNote" name)))
 (if (and note-uri (> (length note-uri) 0))
 (djcb-call-tomboy "SetNoteContents" note-uri
 (concat name "\n" (buffer-substring b e)))
 (message "hmmm... it did not work. maybe try a different name"))))

(defun djcb-tomboy-insert-note-contents (name)
 "Insert Tomboy note with NAME"
 (list (let ((lst))
 (dolist (uri (djcb-call-tomboy "ListAllNotes"))
 (add-to-list 'lst (djcb-call-tomboy "GetNoteTitle" uri)))
 (completing-read "Name of Tomboy Note:" lst))))
 (let ((note-uri (djcb-call-tomboy "FindNote" name)))
 (when note-uri
 (insert (djcb-call-tomboy "GetNoteContents" note-uri)))))

尝试, 选中一个区域, 再运行M-x djcb-tomboy-create-note-region后, 会在tomboy下以当前内容创建一个新的日记

10.22.3 useful link

The Cliffs of Inanity &rsaquo; Emacs and D-Bus
emacs-fu: using d-bus: an example

10.23 emacs smart locate: combine find-name-dired, find-tag and org-mode searching

CLOSED: 2011-10-29 Sat 16:38

(global-set-key "\M-." 'smart-locate)
(defun smart-locate ()
  "Smart locate files.
 - If current position is org-mode file, call occur-org-title, which only search in titles of org-mode entires.
 - If current position has no words, call my-find-name-dired, which is somewhat find-name-dired.
 - Otherwise, call etags-select-find-tag.
  (if (string-equal mode-name "Org")
    (let ((bounds (bounds-of-thing-at-point 'word)))
      (if (null bounds)

(defun my-find-name-dired ()
  (let (pattern)
    (setq pattern (read-shell-command "Find-name (filename wildcard): " nil nil))
    (find-dired default-directory (concat find-name-arg " " (shell-quote-argument pattern)))

(defun occur-org-title()
  "when regexp search, only search title of org-mode entries"
  (let (regexp)
    (setq regexp (read-string "Search org entries whose title matching regexp: " "^\\\*+ .*"))
    (occur-1 regexp 0 (list (current-buffer)))))

10.24 toggle mode-line: mode-line is still a distraction

CLOSED: 2011-12-04 Sun 23:07

10.24.1 basic use

Some advocates of Emacs will say "just run emacs in a full-screen" or something along
those lines, but I find sometimes that the mode-line is still a distraction.

(defun toggle-mode-line () "toggles the modeline on and off"
  (setq mode-line-format
    (if (equal mode-line-format nil)
        (default-value 'mode-line-format)) )

(global-set-key [M-f12] 'toggle-mode-line)

10.25 将shell-command的输出, 存成变量

CLOSED: 2011-11-26 Sat 10:42

  (shell-command "hostname" (current-buffer))
  (setq hostname-val (replace-regexp-in-string "\n" "" (buffer-string))))

10.26 when searching codes, 不区分大小写

CLOSED: 2011-11-26 Sat 15:10
(make-local-variable ‘case-fold-search)
(setq case-fold-search nil)

10.27 flush-words: leave empty whitespace

CLOSED: 2011-12-18 Sun 10:32

(defun flush-words (regexp &optional rstart rend interactive)
  "Delete words containing matches for REGEXP.

If REGEXP contains upper case characters (excluding those preceded by `\\')
and `search-upper-case' is non-nil, the matching is case-sensitive.

Second and third arg RSTART and REND specify the region to operate on.
Lines partially contained in this region are deleted if and only if
they contain a match entirely contained in it.

Interactively, in Transient Mark mode when the mark is active, operate
on the contents of the region. Otherwise, operate from point to the
end of (the accessible portion of) the buffer. When calling this function
from Lisp, you can pretend that it was called interactively by passing
a non-nil INTERACTIVE argument.

If a match is split across lines, all the lines it lies in are deleted.
They are deleted _before_ looking for the next match. Hence, a match
starting on the same line at which another match ended is ignored."

     (list (read-regexp "Flush words containing match for regexp"
                        (thing-at-point 'word)) nil nil t)))
  (if rstart
        (goto-char (min rstart rend))
        (setq rend (copy-marker (max rstart rend))))
    (if (and interactive transient-mark-mode mark-active)
        (setq rstart (region-beginning)
              rend (copy-marker (region-end)))
      (setq rstart (point)
            rend (point-max-marker)))
    (goto-char rstart))
  ;; remove the matching words, and add necessary whitespaces
  (setq regexp (format "%s%s%s" "[ \\n][^ \\n]*" regexp "[^ \\n]*[ \\n]"))
  (message regexp)
  (while (re-search-forward regexp nil t)
    (replace-match (list-to-string
                    (make-list (length (match-string 0)) " "))
                   nil nil))

10.28 emacs rectangle enhancement    IMPORTANT

CLOSED: 2011-12-17 Sat 23:01

  • 剪切一个矩形同时将其清空;
  • 在当前位置粘贴一个矩形
  • 快速选择矩形

(define-key ctl-x-map "r\C-x" 'rm-kill-clean-region)
(define-key ctl-x-map "r\C-y" 'yank-rectangle-in-place)
(define-key ctl-x-map "r\C-m" 'mark-rectangle)
(defun mark-rectangle ()
  "Automatically mark a rectangle, when cursor is in the left corner"
  (let ((rectangle-corner-ch "\+")
        (rectangle-vertical-ch "\|")
        (start-point nil) (end-point nil))
    (when (search-forward-regexp rectangle-corner-ch nil t)
      (setq start-point (- (point) 1))
      ;; (search-forward-regexp "\\+ \\|\n" nil t)
      (when (search-forward-regexp (format "%s \\|\n" (regexp-quote rectangle-corner-ch)) nil t)
        (forward-char -2)
        (setq column-num (current-column))
        (forward-line 1)
        (forward-char column-num))
      ;; keep going downstair
      (while (= (char-after) (string-to-char rectangle-vertical-ch))
        (forward-line 1)
        (forward-char column-num))
      (if (= (char-after) (string-to-char rectangle-corner-ch))
          (setq end-point (+ (point) 1)))
      ;; mark the rectangle, if it's found
      (when (and start-point end-point)
        ;; (rm-deactivate-mark)
        (goto-char start-point)
        (rm-set-mark t)
        (goto-char end-point)
        (rm-exchange-point-and-mark t))

(defun rm-kill-clean-region (start end)
  "Cut a rectangle and clear the region
Like rm-kill-region except the rectangle is also cleared."
  (interactive "r")
  (rm-kill-ring-save start end)
  (clear-rectangle start end)
  (and (interactive-p)

(defun yank-rectangle-in-place ()
  "Like yank-rectangle except the change is taken in place with no new characters created."
  (let ((start (point)) end
        (start-column (current-column)) end-column
        kill-start kill-end)
    ;; yank rectangle
    (setq end (point)
          end-column (current-column))
    (setq rectangle-width (- end-column start-column))
    ;; make sure this line has enough characters
      (move-end-of-line nil)
      (insert (list-to-string (make-list rectangle-width " "))))
    ;; remove useless rectangle, without saving
    (forward-char rectangle-width)
    (setq kill-end (point))
    (goto-char start)
    (forward-char rectangle-width)
    (setq kill-start (point))
    (delete-rectangle kill-start kill-end)))

10.28.1 sample data

                                                        |                     bang                    |
                                                        |                                             |
                                                        |                                             |
                                                        |   +------------+                            |
                                                        |   | FS on fuse |                            |
                                                        |   +------------+                            |
                                                        |        |                                    |
                                                        |        |                                    |
                                                        |    +---+--+      +------+      +------+     |
+----------------------------------+                    |    |  S3  |      | FTP  |      | HTTP |     |
|                                  |                    |    +------+      +------+      +------+     |
|             FS client            |                    |        \             |                      |
|                                  |                    +---------\------------+----------------------+
|           +---------+            |                               \           |
|           | Website |            |                                \          |
|           +---------+            |                                 \         |  common storage api
|                                  |                            +--------------------+
|           +------+               |                            |   common library   |
|           | PHP  |               |                            +--------------------+
|           +------+               |                                      |      K/V DB api
|                                  |                                      |
|                                  |                                      |
+----------------------------------+                                      |
                                                                  |   K/V DB   |

10.29 在发送邮件时, 确认是否用126邮箱来发送    IMPORTANT

CLOSED: 2011-12-22 Thu 00:29

(defun check-from-mail ()
  "Check whether I am sending from company's email adress, when coping with work stuff"
    (let ((working-mail "@shopex.cn")
          (confirm-msg "Are you sure sending from denny.zhang001@gmail.com for shopex emails! ")
      (goto-char (point-min))
      (when (search-forward-regexp (regexp-quote working-mail) nil t)
        ;; make sure we are senging from company's email address
        (goto-char (point-min))
        (unless (search-forward-regexp (format "\\(From: .*%s\\)" working-mail) nil t)
          (yes-or-no-p confirm-msg))
(add-hook 'message-send-mail-hook 'check-from-mail)

10.30 emacs在查看代码时,只显示缩进小于当前缩进的代码框架

CLOSED: 2012-02-18 Sat 00:22

(defun loccur-skeleton ()
  "Call `loccur' for code skeleton with the same leading whitespace."
  (let ((point-orig (point)) leading-str (whitespace-count 0))
      (move-beginning-of-line nil)
      (setq leading-str (buffer-substring-no-properties point-orig (point)))
      (dolist (ch (string-to-list leading-str))
        (if (eq ch 32)
            (setq whitespace-count (+ 1 whitespace-count))
    (unless (eq 0 whitespace-count)
      (loccur (format "^ \\{1,%d\\}[^ ]\\|^[^ ]" whitespace-count)))))
(define-key global-map [(control meta u)] 'loccur-skeleton)
(set-face-background 'isearch "#537182")
(set-face-foreground 'isearch "AntiqueWhite2")

10.31 emacs定义快捷键, 来快速备份当前文件的内容

CLOSED: 2012-03-14 三 22:33

(global-set-key [(meta p)(b)] 'backup-current-file)
(defun backup-current-file (&optional backup_dir)
  (let ((bfilename (file-name-nondirectory (buffer-file-name))))
    (if (null backup_dir) (setq backup_dir "/tmp/"))
    (write-region (point-min) (point-max) (format "%s/%d-%s" backup_dir (random 10000) bfilename))

11 Compare and diff in emacs

11.1 ediff    IMPORTANT

Command Operation
M-x ediff Enter ediff mode
a Copy file A’s region to file B’s. (A wins)
b Copy file B’s region to file A’s. (B wins)
? Help
n Move to next difference region
p Move to previous difference region
ra Restore A’s region (after a b operation)
rb Restore B’s region (after an a operation)
A Make buffer A read-only
B Make buffer B read-only
q Quit ediff

11.1.1 比较当前两个buffer: ediff-buffers

Ediff is an easy way to compare two versions of a file. The most
common way I activate is with M-x ediff-buffers. Emacs highlights the
differing regions in the buffers and pops up a new window in which
you can enter additional commands. For example, n and p move among
differing regions in the buffers. For each region, you can copy the
first (or second) buffer's version to the other buffer with a and b,
respectively. You can even edit either buffer while Ediff is
active. Then you can switch back to the Ediff window and press ! to
recompute the diff. Being able to view the differences between two
files interactively— while editing those files— can be really useful.


Essential Emacs tips

11.1.2 useful link

11.2 emacs ediff给出两行不相同的字符

CLOSED: 2012-04-22 日 09:33
g++ -I/usr/include -I/usr/local/include -I/opt/local/include -I/usr/include/thrift -I/usr/local/include/thrift -I/opt/local/include/thrift -I/usr/include/thrift -I/usr/include -DPACKAGE_NAME=\”smc\” -DPACKAGE_TARNAME=\”smc\” -DPACKAGE_VERSION=\”1.0\” -DPACKAGE_STRING=\”smc\ 1.0\” -DPACKAGE_BUGREPORT=\”denny.zhang001@gmail.com\” -DCPU_VENDOR_OS=\”x86_64-unknown-linux-gnu\” -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBZOOKEEPER_MT=1 -DHAVE_LIBTHRIFT=1 -DHAVE_BOOST_SHARED_PTR_HPP=1 -o libsmc_lib.so -fPIC -shared -Iinclude -I./include/thrift_cpp ./include/thrift_cpp/EcaeService.cpp ./include/thrift_cpp/ecae303_types.cpp ./include/thrift_cpp/ecae303_constants.cpp src/thrift_ecae.cpp ./src/smc_lib.cpp ./src/erl_comm.cpp -L/usr/lib -L/usr/local/lib -L/opt/local/lib -L/usr/lib -L/usr/lib -lpthread -lthrift -lzookeeper_mt

g++ -I/usr/include -I/usr/local/include -I/opt/local/include -I/usr/include/thrift -I/usr/local/include/thrift -I/opt/local/include/thrift -I/usr/local//include/thrift -I/usr/include -DPACKAGE_NAME=\”smc\” -DPACKAGE_TARNAME=\”smc\” -DPACKAGE_VERSION=\”1.0\” -DPACKAGE_STRING=\”smc\ 1.0\” -DPACKAGE_BUGREPORT=\”denny.zhang001@gmail.com\” -DPACKAGE_URL=\”\” -DCPU_VENDOR_OS=\”i686-pc-linux-gnu\” -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBZOOKEEPER_MT=1 -DHAVE_LIBTHRIFT=1 -DHAVE_BOOST_SHARED_PTR_HPP=1 -o libsmc_lib.so -fPIC -shared -Iinclude -I./include/thrift_cpp ./include/thrift_cpp/EcaeService.cpp ./include/thrift_cpp/ecae303_types.cpp ./include/thrift_cpp/ecae303_constants.cpp src/thrift_ecae.cpp ./src/smc_lib.cpp ./src/erl_comm.cpp -L/usr/lib -L/usr/local/lib -L/opt/local/lib -L/usr/local//lib -L/usr/lib -lpthread -lthrift -lzookeeper_mt

(defun ediff-sequent-lines ()
  "Compare two sequent lines in the same buffer, by calling ediff-regions-internal"
  (let ((fc (current-frame-configuration)))
     `(defun rfc ()
        (set-frame-configuration ',fc)
        (remove-hook 'ediff-after-quit-hook-internal 'rfc)))
    (add-hook 'ediff-after-quit-hook-internal 'rfc)
     (current-buffer) (line-beginning-position) (line-end-position)
     (current-buffer) (line-beginning-position 2) (line-end-position 2)
     nil 'ediff-windows-wordwise 'word-mode nil)))

11.3 M-x diff-backup: Diff this file with its backup file or vice versa.    IMPORTANT

CLOSED: 2011-12-01 Thu 10:49

11.4 M-x compare-windows: compares the text in the current window with that in the next window.

CLOSED: 2011-12-01 Thu 10:51

12 Flymake in emacs

Minor mode to do on-the-fly syntax checking

12.1 basic use

Flymake runs the syntax check tool in the background, passing it a temporary copy of the current buffer,
and parses the output for known error/warning message patterns.

12.2 support for html: 调用tidy来检查html的完整度

CLOSED: 2011-07-14 Thu 15:53

sudo apt-get install tidy

tidy – validate, correct, and pretty-print HTML files

tidy -f errs.txt -m index.html

12.2.1 console shot: flymake fails to open, since missing tidy

Failed to launch syntax check process 'tidy' with args. Searching for program: no such file or directory, tidy: Flymake will be switched OFF

12.3 support for elisp: 调用emacs, scan-sexps来检查没有配对的括号

CLOSED: 2011-07-14 Thu 17:33

EmacsWiki: Flymake Elisp

;;flymake for elisp mode
(defun flymake-elisp-init ()
 (unless (string-match "^ " (buffer-name))
 (let* ((temp-file (flymake-init-create-temp-buffer-copy
 (local-file (file-relative-name
 (file-name-directory buffer-file-name))))
 (expand-file-name invocation-name invocation-directory)
 "-Q" "--batch" "--eval"
 (dolist (file command-line-args-left)
 (insert-file-contents file)
 (condition-case data
 (scan-sexps (point-min) (point-max))
 (goto-char(nth 2 data))
 (princ (format "%s:%s: error: Unmatched bracket or quote\n"
 file (line-number-at-pos)))))))
(push '("\\.el$" flymake-elisp-init) flymake-allowed-file-name-masks)
(add-hook 'emacs-lisp-mode-hook
 ;; workaround for (eq buffer-file-name nil)
 (function (lambda () (if buffer-file-name (flymake-mode)))))

12.4 support for css: 通过python的cssutils来作为W3C的validator

CLOSED: 2011-07-14 Thu 19:58
sudo easy_install cssutils

12.5 support for ruby: ruby -c filename来检查语法问题

CLOSED: 2011-07-14 Thu 20:32

12.6 flymake for python    IMPORTANT

CLOSED: 2011-07-27 Wed 11:39
sudo apt-get install pyflakes
sudo apt-get install pep8

sudo ln -s /usr/local/bin/pep8 /usr/bin/pep8.py

12.6.1 pylint

12.6.2 pyflakes: analyze Python programs and detect various errors.

pyflakes 0.4.0 : Python Package Index

12.6.3 pep8 – Python style guide checker


 Plugin architecture: Adding new checks is easy.
 Parseable output: Jump to error location in your editor.
 Small: Just one Python file, requires only stdlib. You can use just the pep8.py file for this purpose.
 Comes with a comprehensive test suite.


 pep8 0.6.1 : Python Package Index


 用PEP 8检查Python Coding风格 &raquo; 豆花@垃圾熊

12.6.4 useful link

python – PyLint, PyChecker or PyFlakes ? – Stack Overflow

12.6.5 PyChecker

pychcker is troublesome because it compiles the module to analyze it.

12.7 support for shell

CLOSED: 2011-07-29 Fri 13:26

12.8 emacs fringe-helper: contains helper functions for fringe bitmaps.

12.9 support for php

CLOSED: 2011-07-29 Fri 13:27

12.9.1 PHP check in emacs: php -f file -l

CLOSED: 2011-07-14 Thu 20:50
sudo pear install PHP_CodeSniffer-1.3.0
The error_reporting option in php.ini needs to include E_PARSE in order for php to report parsing error details. php -l: syntax check only(lint) PHP_CodeSniffer: 代码检测的php脚本

PHP_CodeSniffer is a PHP5 script that tokenises PHP, JavaScript and CSS files to detect violations of a defined coding standard.

  • 配置

    - sudo pear install PHP_CodeSniffer-1.3.0
    - Sample .emacs file: skill.org
    (defun my-php-hook-function ()
     (set (make-local-variable 'compile-command) (format "phpcs --report=emacs --standard=PEAR %s" (buffer-file-name))))
    (add-hook 'php-mode-hook 'my-php-hook-function)

  • phpcs -s –report=summary /path/to/code

12.10 support for python

CLOSED: 2011-07-29 Fri 13:29

12.10.1 useful link

12.11 Flymake-cursor.el — displays flymake error msg in minibuffer after delay (by Dino Chiesa)

12.13 ;; § ————————– separator ————————–

12.14 CANCELED flymake filter some output

CLOSED: 2011-09-10 Sat 17:46

12.15 disable flymake in tramp buffers

CLOSED: 2011-12-22 Thu 00:59
(unless (or (null buffer-file-name) (tramp-file-name-p buffer-file-name)) (flymake-mode t))

;;flymake for shell mode
(defun flymake-shell-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
         (local-file (file-relative-name
                      (file-name-directory buffer-file-name))))
    (list "/bin/bash" (append (list "-n") (list local-file)))))

(defun my-shell-hook-function ()
  (set (make-local-variable 'compile-command)
       (format "/bin/bash -c %s" (buffer-file-name))))

(add-to-list 'flymake-allowed-file-name-masks '("\\.sh$" flymake-shell-init))
(add-hook 'sh-mode-hook
             (unless (or (null buffer-file-name) (tramp-file-name-p buffer-file-name)) (flymake-mode t))
             (make-local-variable 'flymake-err-line-patterns)
             (setq flymake-err-line-patterns
                   '(("^\\(.+\\): line \\([0-9]+\\): \\(.+\\)$" 1 2 nil 3)))))

12.15.1 useful link

13 Emacs GDB

  • 编译时, 使用-g生产debug信息
命令 功能
gdb 启动gdb进行调试
gdb-many-windows 切换单窗格/多窗格模式
gdb-restore-windows 恢复窗格布局
功能 命令 默认快捷键
添加断点 gud-break C-x C-a C-b 或 C-x <SPC>
删除断点 gud-remove C-x C-a C-d
运行/继续程序 gud-go
单步执行,无视函数 gud-next C-x C-a C-n
单步执行,进入函数 gud-step C-x C-a C-s
跳出当前函数 gud-finish C-x C-a C-f
运行到光标所在语句 gud-until C-x C-a C-u
继续运行程序 gud-cont C-x C-a C-r

13.1 sample

  • gcc -g test.c -o prog
  • gdb
  • gdb-many-windows

13.1.1 test.c

int fun() {
  int i = 1;
  i = i + 1;
  return i;

int main (int argc, char * argv[])
  printf("hello, world\n");
  return 0;

14 Games in emacs

Name Command
俄罗斯广场 M-x tetris
贪食蛇 M-x snake
心理医生 M-x doctor
五子棋 M-x gomoku
汉诺塔动画 M-x hanoi
Black Box M-x blackbox
Conway’s Game of Life M-x life
动画显示生日快乐 M-x animate-birthday-present

15 Artist-mode

  • 绘制操作(鼠标左键)
操作 无shift shift
pen 单击,在鼠标点填充一个“填充符号”,默认为”.”;按下左键,拖动,抬起,绘制填充符号组成的线 单击,在鼠标点填充一个“o”;按下左键,拖动,抬起,绘制一条从初始点到最终点的直线
Line 任意方向的线 直线
Rectangle 矩形 正方形1
Poly-line 任意方向的多边形 每条线都是直线的多边形
Ellipses 椭圆 圆2
Text 文本 覆盖式文本
Spray-can 喷雾器3 设置喷雾器的大小
Erase 橡皮,擦掉一个字符 擦掉矩形内字符
Vaporize 擦除一行 擦除所有相连的行
Cut 剪切矩形 剪切正方形
copy 复制矩形 复制正方形
paste 粘贴 粘贴
Flood-fill 填充工具,填充 填充

16 source code build emacs

  • install basic packages: sudo apt-get install texinfo libxpm-dev libtiff-dev libgit-dev
  • install imagemagick: imagemagick libmagick++9-dev libmagic-dev libmagics++-dev
  • download source code
  • sh ./autogen.sh
  • ./configure –with-crt-dir=/usr/lib/x86_64-linux-gnu

16.1 configure: error: crt*.o not found. Use –with-crt-dir to specify the location.

16.2 ./configure: Does Emacs use -lm17n-flt? no: sudo apt-get install libm17n-dev

CLOSED: 2012-04-11 三 00:35

16.3 configure: error: You do not seem to have makeinfo >= 4.6: sudo apt-get install texinfo

16.4 configure error: libXpm libgif/libungif libtiff没找到: sudo apt-get install libxpm-dev libtiff-dev libgit-dev

16.6 web page: Installing Emacs 23 from Bazaar source on Ubuntu Karmic « SaltyCrane Blog

17 Emacs Speaks Statistics    IMPORTANT

sudo apt-get install r-base r-base-html r-doc-html ess r-doc-info r-cran-coda

Item Comment
ess-load-file (C-c C-l) Load an S source file into an inferior ESS process.
ess-eval-region(C-c C-r)

17.2 sample

> x <- runif(10)
> ls()
[1] "x"
> y <- data.frame(col1=c("a", "b", "c"), col2=c(1,2,3))
> y$col
> y$col1
[1] a b c
Levels: a b c
> y$col2
[1] 1 2 3
> x
 [1] 0.3381927 0.5502567 0.5874121 0.6026629 0.3189729 0.6198550 0.3781260
 [8] 0.2423674 0.3865660 0.5078231
> q()
Save workspace image? [y/n/c]: y

Process R finished at Sun Apr 22 23:47:39 2012

17.3 CANCELED Searching for program: no such file or directory, Splus8

CLOSED: 2012-04-23 一 07:55
S-PLUS/R统计论坛 : SPLUS8预览-包系统简介

18 emacs bookmark

Bookmark directories
Bookmark proejcts

 C-x r l List all bookmarks
;; § -------------------------- separator --------------------------


Bookmarks. Emacs bookmarks are both named and persistent, two features that many editors fail to offer.

They are invaluable because not only can I save my place in a file, I can also bookmark a directory that will be opened with Dired. I use them to jump to my most visited locations on the file system, and my main Org Mode files. Having a bookmark which effortlessly takes me where I want to go prevents me from losing my focus while I click around in the Finder or Windows Explorer.

I manage large numbers of bookmarks by namespacing them - all of my Org file bookmarks start with 'org' for example. This makes it easier to find a bookmark with tab-completion.

How to use them:

 C-x r m BOOKMARK <RET> Set the bookmark named BOOKMARK at point (`bookmark-set').

 C-x r b BOOKMARK <RET> Jump to the bookmark named BOOKMARK (`bookmark-jump').

 C-x r l List all bookmarks (`list-bookmarks').

I'm still waiting for Visual Studio to introduce named bookmarks - you need to install ReSharper just to get numbered ones!

19 Emacs register

Item Command
window-configuration-to-register(C-x r w) 可以记录当前的窗口布局,包括光标位置
jump-to-register(C-x r j) 输入寄存器的名字,就可以跳转到原来保存的位置了
point-to-register(C-x r SPC) 保存当前光标位置
copy-to-register(C-x r x) 拷贝一段文字
insert-register(C-x r i) Insert contents of register REGISTER

19.1 web page: Emacs中的Register

20 Animation — 动画

Name Command
M-x zone
M-x butterfly

21 emacs使用gtalk


Item Comment
登录 M-x jabber-connect-all
退出 M-x jabber-disconnect
要添加某人为好友 M-x jabber-send-subscription-request
将状态设置为away C-x C-j C-a – away
将状态设置为extended away C-x C-j C-x – extended away
将状态设置为online C-x C-j C-o – online
更新某个人的头像 jabber-vcard-avatars-fetch

21.1 jabber中away的色彩不容易分辨

CLOSED: 2012-07-28 六 00:29

   ((t (:foreground "forest green" :slant normal :weight bold))))
   ((t (:foreground "LightSteelBlue3" :slant italic :weight normal))))
   ((t (:inherit variable-pitch :weight bold :height 1.5 :width ultra-expanded))))
   ((t (:inherit variable-pitch :foreground "#E8E8E8" :weight
                 bold :height 1.1 :width semi-expanded))))
   ((t (:inherit variable-pitch :foreground "#adc4e3" :weight
                 bold :height 0.7 :width semi-expanded)))))

21.2 快速跳到jabber的主页面: (jabber-switch-to-roster-buffer) C-x C-j C-r

CLOSED: 2012-07-28 六 00:29

21.3 默认登录时,设置为away的状态: (add-hook ‘jabber-post-connect-hooks #’(lambda (x) (jabber-send-away-presence)) t)

CLOSED: 2012-07-28 六 10:00

21.4 当状态变更时,动态显示签名档

CLOSED: 2012-07-28 六 09:37

;; dynamically set status string
(defadvice jabber-send-presence (after let activate)
  (setq *jabber-current-status* (get-motto 30))
  (setq jabber-default-status *jabber-current-status*)

21.5 Don’t disturb me if someone change presence status

CLOSED: 2012-07-28 六 15:30

(remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)

22 useful webpage

22.1 web page: The Ultimate Collection of Emacs Resources – (think)

22.2 web page: 一年成为Emacs高手(像神一样使用编辑器) 陈斌的博客

23 Enable image-mode to view previous/next image

CLOSED: 2012-04-23 一 22:06

(add-to-list 'auto-mode-alist '("\\.jpeg$" . image-mode))
(add-to-list 'auto-mode-alist '("\\.jpg$" . image-mode))
(define-key image-mode-map (kbd "n") '(lambda() (interactive) (rotate-image-in-directory 1)))
(define-key image-mode-map (kbd "p") '(lambda() (interactive) (rotate-image-in-directory -1)))
(defun rotate-image-in-directory (N)
  "Enable image-mode to view previous/next image"
 (let* ((current-file (file-name-nondirectory (buffer-file-name)))
        (old-buffer (current-buffer))
        (file-list (directory-files "." nil ".*jpg\\|.*jpeg"))
        (file-count (length file-list))
   (setq index (mod
                (+ file-count (+ N (position current-file file-list :test #'equal)))
   (find-file (nth index file-list))
   (kill-buffer old-buffer)

24 emacs gtalk的异常

CLOSED: 2012-08-01 三 22:43
(image-type “/home/denny/backup/essential/Dropbox/private_data/emacs_stuff/jabber/avatars/14370fff97373910a64095f35c3f123150314485″ nil nil)

(add-to-list ‘image-type-header-regexps ‘(“\\`\211PNG\n\n” . png))

25 emacs open pdf failure: seems error is raised by intention

CLOSED: 2012-10-14 日 22:32

(defun openwith-file-handler (operation &rest args)
  "Open file with external program, if an association is configured."
  (when (and openwith-mode (not (buffer-modified-p)) (zerop (buffer-size)))
    (let ((assocs openwith-associations)
          (file (car args))
      ;; do not use `dolist' here, since some packages (like cl)
      ;; temporarily unbind it
      (while assocs
        (setq oa (car assocs)
              assocs (cdr assocs))
        (when (save-match-data (string-match (car oa) file))
          (let ((params (mapcar (lambda (x) (if (eq x 'file) file x))
                                (nth 2 oa))))
            (when (or (not openwith-confirm-invocation)
                      (y-or-n-p (format "%s %s? " (cadr oa)
                                        (mapconcat #'identity params " "))))
              (apply #'start-process "openwith-process" nil (cadr oa) params)
              (kill-buffer nil)
              ;; inhibit further actions
              (error "Opened %s in external program"
                     (file-name-nondirectory file))))))))
  ;; when no association was found, relay the operation to other handlers
  (let ((inhibit-file-name-handlers
         (cons 'openwith-file-handler
               (and (eq inhibit-file-name-operation operation)
        (inhibit-file-name-operation operation))
    (apply operation args)))
Debugger entered--Lisp error: (error "Opened Denny-Linux-CV-CoverLetter.doc in external program")
  signal(error ("Opened Denny-Linux-CV-CoverLetter.doc in external program"))
  error("Opened %s in external program" "Denny-Linux-CV-CoverLetter.doc")
  (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file)))
  (if (or (not openwith-confirm-invocation) (y-or-n-p (format "%s %s? " (cadr oa) (mapconcat (function identity) params " ")))) (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file))))
  (let ((params (mapcar (function (lambda (x) (if (eq x ...) file x))) (nth 2 oa)))) (if (or (not openwith-confirm-invocation) (y-or-n-p (format "%s %s? " (cadr oa) (mapconcat (function identity) params " ")))) (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file)))))
  (progn (let ((params (mapcar (function (lambda (x) (if ... file x))) (nth 2 oa)))) (if (or (not openwith-confirm-invocation) (y-or-n-p (format "%s %s? " (cadr oa) (mapconcat (function identity) params " ")))) (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file))))))
  (if (let ((save-match-data-internal (match-data))) (unwind-protect (progn (string-match (car oa) file)) (set-match-data save-match-data-internal (quote evaporate)))) (progn (let ((params (mapcar (function (lambda ... ...)) (nth 2 oa)))) (if (or (not openwith-confirm-invocation) (y-or-n-p (format "%s %s? " (cadr oa) (mapconcat ... params " ")))) (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file)))))))
  (while assocs (setq oa (car assocs) assocs (cdr assocs)) (if (let ((save-match-data-internal (match-data))) (unwind-protect (progn (string-match (car oa) file)) (set-match-data save-match-data-internal (quote evaporate)))) (progn (let ((params (mapcar (function ...) (nth 2 oa)))) (if (or (not openwith-confirm-invocation) (y-or-n-p (format "%s %s? " ... ...))) (progn (apply (function start-process) "openwith-process" nil (cadr oa) params) (kill-buffer nil) (error "Opened %s in external program" (file-name-nondirectory file))))))))
  (let ((assocs openwith-associations) (file (car args)) oa) (while assocs (setq oa (car assocs) assocs (cdr assocs)) (if (let ((save-match-data-internal (match-data))) (unwind-protect (progn (string-match (car oa) file)) (set-match-data save-match-data-internal (quote evaporate)))) (progn (let ((params (mapcar ... ...))) (if (or (not openwith-confirm-invocation) (y-or-n-p ...)) (progn (apply ... "openwith-process" nil ... params) (kill-buffer nil) (error "Opened %s in external program" ...))))))))
  (progn (let ((assocs openwith-associations) (file (car args)) oa) (while assocs (setq oa (car assocs) assocs (cdr assocs)) (if (let ((save-match-data-internal (match-data))) (unwind-protect (progn (string-match ... file)) (set-match-data save-match-data-internal (quote evaporate)))) (progn (let ((params ...)) (if (or ... ...) (progn ... ... ...))))))))
  (if (and openwith-mode (not (buffer-modified-p)) (zerop (buffer-size))) (progn (let ((assocs openwith-associations) (file (car args)) oa) (while assocs (setq oa (car assocs) assocs (cdr assocs)) (if (let ((save-match-data-internal ...)) (unwind-protect (progn ...) (set-match-data save-match-data-internal ...))) (progn (let (...) (if ... ...))))))))
  openwith-file-handler(insert-file-contents "/home/denny/backup/essential/Dropbox/private_data/jb/Denny-Linux-CV-CoverLetter.doc" t nil nil nil)
  insert-file-contents("~/backup/essential/Dropbox/private_data/jb/Denny-Linux-CV-CoverLetter.doc" t)
  byte-code("\302\303   \302\"\210)\302\207" [inhibit-read-only filename t insert-file-contents] 3)
  find-file-noselect-1(#<killed buffer> "~/backup/essential/Dropbox/private_data/jb/Denny-Linux-CV-CoverLetter.doc" nil nil "~/backup/essential/Dropbox/private_data/jb/Denny-Linux-CV-CoverLetter.doc" (2638995 2053))
  find-file-noselect("/home/denny/backup/essential/Dropbox/private_data/jb/Denny-Linux-CV-CoverLetter.doc" nil nil nil)
  call-interactively(dired-find-file nil nil)

26 emacs gnus的定时邮件, 支持可以指定一天后的几点几分发送: gnus-delay-default-hour

CLOSED: 2012-10-20 六 14:22

27 org-mode add http link

CLOSED: 2014-05-18 Sun 22:27
format: [[link] [description]]

28 change #+OPTIONS: toc:nil

CLOSED: 2014-05-19 Mon 00:12
(setq org-export-with-toc nil)

29 org-mode export image

By Denny 06/26/14