Saturday, November 24, 2007

Friday, November 16, 2007

[Emacs Tips] 注释

M-x comment-dwim (Do What I Mean) 是最聪明的一种注释方式。如果已经选定了区域,那么就是注释或者反注释;如果没有选定区域,那么就是在这行末尾添加注释。

默认的键绑定是 M-;

注释还可以选择不同的模式,不同注释符号,在不同的编程语言模式下都不同。

控制注释符号的是变量 comment-start 和 comment-end,用 C-h v 查看,用例如 (setq comment-start "//") 修改。

变量 comment-style 控制注释的样式。可以用例如 (setq comment-style 'box) 修改。
以下是各种注释风格的示例。

int main()
{
/* this is a comment line. */
/* comment style 'plain */

/* this is a comment line. */
/* comment style 'indent */

/* this is a comment line. */
/* comment style 'aligned */

/* this is a comment line.
* comment style 'multi-line */

/*
* this is a comment line.
* comment style 'extra-line
*/

/***************************/
/* this is a comment line. */
/* comment style 'box */
/***************************/

/****************************
* this is a comment line. *
* comment style 'box-multi *
****************************/
}
再提供一个直接注释一行的函数。有时候比 comment-dwim 更有效。有选中区域的话就是注释或反注释这个区域;反之注释或者反注释光标所在的行。
(defun huangq-comment-dwim (&optional n)
"Comment do-what-i-mean"
(interactive "p")
(apply 'comment-or-uncomment-region
(if (and mark-active transient-mark-mode)
(list (region-beginning) (region-end))
(if (> n 0)
(list (line-beginning-position) (line-end-position n))
(list (line-beginning-position n) (line-end-position))))))

[Emacs Tips] 插入相邻一行的字符

类似于 VIM 插入状态下的 C-y 和 C-e,也就是插入光标所在上一行或者下一行的字符。
例如: VIM 插入状态下的 C-y 和 C-e,也就是插入光标所在上一行或者下一行的字符。

写程序的时候还是挺有用的
;;;###autoload
(defun my-insert-char-next-line (arg)
"insert char below the cursor"
(interactive "p")
(let ((col (current-column))
char)
(setq char
(save-excursion
(forward-line arg)
(move-to-column col)
(if (= (current-column) col)
(char-after))))
(if char
(insert-char char 1)
(message (concat "Can't get charactor in "
(if (< arg 0)
"previous"
"next")
(progn (setq arg (abs arg))
(if (= arg 1) ""
(concat " " (number-to-string arg))))
" line.")))))

;;;###autoload
(defun my-insert-char-prev-line (arg)
"insert char above the cursor"
(interactive "p")
(my-insert-char-next-line (- arg)))
用的键绑定是 C-x (C-x )
(global-set-key (kbd "C-)") 'my-insert-char-next-line)
(global-set-key (kbd "C-(") 'my-insert-char-prev-line)

Wednesday, November 14, 2007

[Emacs Tips] isearch 查找 (2)

注:有些函数非原创,因为年代长久,很难找到出处,就不一一注明了。

一些加快查找速度的函数。

1. 查找选定区域的内容。Emacs 有无数用来选定 (mark) 的函数,所以选定容易,但是没有直接查找选定内容的函数。下面这个函数提供此功能,按 F3 就是 isearch 当前选定的词,继续按 C-s 就可以查找了。

(defvar my-isearch-string nil)
(setq my-isearch-string "")

(defun my-isearch-region-forward ()
"isearch region if mark is acktive"
(interactive)
(if mark-active
(let ((beg (region-beginning))
(end (region-end)))
(setq my-isearch-string (filter-buffer-substring beg end nil))
(deactivate-mark)
(if (> (length my-isearch-string) 0)
(progn
(goto-char beg)
(isearch-update-ring my-isearch-string)
(add-hook 'isearch-mode-end-hook 'my-isearch-end-hook)
(isearch-mode t) ;hack isearch-forward
(isearch-repeat 'forward)
(message "%s" isearch-string)))) ;print debug msg
(if (> (length my-isearch-string) 0)
(progn
(isearch-repeat 'forward))
(message "no region selected")
)))

(global-set-key (kbd "<f3>") 'my-isearch-region-forward)

(defun my-isearch-end-hook ()
(remove-hook 'isearch-mode-end-hook 'my-isearch-end-hook)
(setq my-isearch-string ""))


2. 查找当前词,类似于 VIM 的 *,这里用的键绑定是 C-* .

(defvar my-isearch-word "")

(defun my-isearch-word ()
  (interactive)
  (when (not mark-active)
    (let (word-beg word-end)
      (unless (looking-at "\\<")
        (if (eq (char-syntax (char-after)) ?w)
            (backward-word)
          (and (forward-word) (backward-word)))
        )
      (setq word-beg (point))
      (forward-word)
      (setq word-end (point))
      (setq my-isearch-word (filter-buffer-substring word-beg word-end nil t))
      (backward-word)
      )
    (when (> (length my-isearch-word) 0)
      (setq my-isearch-word (concat "\\<" my-isearch-word "\\>"))
      (isearch-update-ring my-isearch-word t)
      (add-hook 'isearch-mode-end-hook 'my-isearch-word-end-hook)
      (isearch-mode t t)
      (isearch-repeat 'forward)
      (message "%s" isearch-string))))

(global-set-key (kbd "C-*") 'my-isearch-word)

(defun my-isearch-word-end-hook ()
  (remove-hook 'isearch-mode-end-hook 'my-isearch-word-end-hook)
  (setq my-isearch-word ""))

Tuesday, November 13, 2007

[Emacs Tips] isearch 查找 (1)

isearch (C-s) 是 Emacs 里最常用的查找方式,也是目前为止我在各种软件里,编辑器里用过最舒服的查找方式。

首先这是 incremental search,也就是递增方式的搜索,一边输入一边就开始查找了;
其次有 lazy highlight 功能,低亮显示 buffer 里所有找到的词。
这个功能是由 isearch-lazy-highlight 这个变量控制的,用 C-h v isearch-lazy-highlight 查看这个变量目前是不是真 t。



isearch-mode 也有很多键绑定,用 C-h f isearch-mode 查看。
具体就不详细写了。最常用的 C-w ,查找当前的词。(明天再给出一个更快更方便的查找方式)

建议可以试试相关的 Elisp 插件 color-moccor.el
用了这个以后可以在 isearch 里敲 M-o,列出文件里的搜索结果; 或者 M-O (大写o) 列出所有 buffer 里的对应结果。

[Emacs Tips] 复制一行

从今天开始打算每天用中文介绍一个 Emacs 小技巧。都是很小的技巧而已。

首先是快速复制一行。基本思想是,光标在哪一行就复制哪一行,不用选定区域。如果区域已经选定了,那么就复制区域。类似于 VIM 的yy。

仍旧使用 M-w 的键绑定,和原先的习惯差不多。使用前提是启用了 transient-mark-mode,即高亮选定区域。实际使用中发现每行开头的空格一点用都没有,而且很碍事,所以今天改了一下,一般从第一个非空格的字符开始复制。

这里提供几个函数。
huangq-save-one-line 是复制一行;如果有参数,则从第一个不是空格的字符开始复制。
huangq-kill-ring-save 如果选定了区域,则复制区域;否则复制行。
huangq-save-line-dwim 如果选定了区域,复制区域;否则从第一个不是空格的字符开始复制。

最后是键绑定:
(global-set-key (kbd "M-w") 'huangq-save-line-dwim)

函数的实现:
;;;###autoload
(defun huangq-save-one-line (&optional arg)
"save one line. If ARG, save one line from first non-white."
(interactive "P")
(save-excursion
(if arg
(progn
(back-to-indentation)
(kill-ring-save (point) (line-end-position)))
(kill-ring-save (line-beginning-position) (line-end-position)))))

;;;###autoload
(defun huangq-kill-ring-save (&optional n)
"If region is active, copy region. Otherwise, copy line."
(interactive "p")
(if (and mark-active transient-mark-mode)
(kill-ring-save (region-beginning) (region-end))
(if (> n 0)
(kill-ring-save (line-beginning-position) (line-end-position n))
(kill-ring-save (line-beginning-position n) (line-end-position)))))

;;;###autoload
(defun huangq-save-line-dwim (&optional arg)
"If region is active, copy region.
If ARG is nil, copy line from first non-white.
If ARG is numeric, copy ARG lines.
If ARG is non-numeric, copy line from beginning of the current line."
(interactive "P")
(if (and mark-active transient-mark-mode)
;; mark-active, save region
(kill-ring-save (region-beginning) (region-end))
(if arg
(if (numberp arg)
;; numeric arg, save ARG lines
(huangq-kill-ring-save arg)
;; other ARG, save current line
(huangq-save-one-line))
;; no ARG, save current line from first non-white
(huangq-save-one-line t))))

Friday, November 02, 2007

flymake mode

How can I miss this wonderful feature until now?

Flymake is amazing. See the screenshot:


What you need is only a Makefile with an extra target "check-syntax":
check-syntax:
    gcc -o nul -Wall -Wextra -fsyntax-only $(CHK_SOURCES)

And of course type "M-x flymake-mode" when needed.

You can also customize the error and warning face in .emacs like:
(require 'flymake nil t)
(when (featurep 'flymake)
(set-face-background 'flymake-errline "LightPink")
(set-face-foreground 'flymake-errline "DarkRed")
(set-face-bold-p 'flymake-errline t)
(set-face-background 'flymake-warnline "LightBlue2")
(set-face-foreground 'flymake-warnline "DarkBlue")
(set-face-bold-p 'flymake-warnline t))

Search word at point in Emacs

查找光标上的单词

The default i-search command in Emacs is C-s, and then type the word you want to search. If your cursor is current on the beginning of the word, then you can type C-s C-w. This is case insensitive.

If you want to look for the exact word, then you can use the following code. Type C-* and search the word at the point. It works just like the Star * in VIM.

(defvar my-isearch-word "")

(defun my-isearch-word ()
(interactive)
(when (not mark-active)
(let (word-beg word-end)
(unless (looking-at "\\<")
(if (eq (char-syntax (char-after)) ?w)
(backward-word)
(and (forward-word) (backward-word)))
)
(setq word-beg (point))
(forward-word)
(setq word-end (point))
(setq my-isearch-word (filter-buffer-substring word-beg word-end nil t))
(backward-word)
)
(when (> (length my-isearch-word) 0)
(setq my-isearch-word (concat "\\<" my-isearch-word "\\>"))
(isearch-update-ring my-isearch-word t)
(add-hook 'isearch-mode-end-hook 'my-isearch-word-end-hook)
(isearch-mode t t)
(isearch-repeat 'forward)
(message "%s" isearch-string))))

(global-set-key (kbd "C-*") 'my-isearch-word)

Monday, September 10, 2007

It's All Text! - A wonderful Firefox extension

It's All Text! is a Firefox extension. With this extension you can edit the text area in a webpage using external editors, e.g. Emacs, VIM, Notepad ... etc.

After installed this extension, restarted Firefox, there will be a small "edit" button at the right bottom corner of a text edit area. For example, Gmail compose message, blogger input box, or comment area. Assign an external editor in the preference of It's All Text!, click this "edit" button or right click on the text area and select It's All Text!, you will be switched to the editor. Type anything and save the file, the text will be copied back to the text edit area in the webpage.

This is a really amazing feature I was looking for since long ago. Under Windows I use a bat file to start emacsclient:

d:\Emacs\bin\emacsclientw.exe -f "PATHTO\.emacs.d\server\server" -a "d:\Emacs\bin\runemacs.exe" -n %1

Select this bat file as the editor for It's All Text!

Of course you need to start server in Emacs first. Add this line into your .emacs file:

(server-start)


Have fun!

Maybe later we can post blog using emacs-muse with this Firefox extension more conveniently. We'll see.

Saturday, August 18, 2007

URLs for Google Maps

It's really convenient to use Google Maps to find specific locations and route. But it's very slow to load the home page of Google Maps every time. However, like Google, it is possible to type the link address directly to find a location in Google Maps. For example, to find Marienplatz 1, you can use the following URL directly:
http://maps.google.de/maps?hl=en&q=Marienplatz%201%2C%20Munich

It is quite neat to use this feature combined with Firefox Bookmark Keyword. You can save http://maps.google.de/maps?hl=en&q=%s as Firefox Bookmark, and name the Keyword of this bookmark as gmap. The next time, you can directly type "gmap Marienplatz 1 Munich" in the Firefox address bar to find this location in Google Maps. Even more, you can type "gmap from Marienplatz 1 Munich to Olympiapark Munich" to find the route.

And here are the other parameters of the URL:

lat and lon: q=48.1374740601+11.5754375458
Comment for info window: (City Hall Munich)
Zoom Level: &z=18
language of map (en=english, fr=french, de=germany): &hl=en
map type (0=street map, k=satellite, h=hybrid): &t=k

The complete URL example:
http://maps.google.de/maps?hl=en&amp;amp;q=48.1374740601+11.5754375458+(City Hall Munich)&t=k&z=18


All Google Maps Parameters:
http://mapki.com/index.php?title=Google_Map_Parameters

Saturday, June 02, 2007

Gnu Emacs Reference Card

pdf version is in emacs directory "/usr/local/share/emacs/23.0.0/etc/refcard.ps"

Starting Emacs

To enter GNU Emacs 22 or 23, just type its name: emacs

Leaving Emacs

suspend Emacs (or iconify it under X) C-z
exit Emacs permanently C-x C-c

Files

read a file into Emacs C-x C-f
save a file back to disk C-x C-s
save all files C-x s
insert another file into this buffer C-x i
replace this file with another file C-x C-v
write buffer to a specified file C-x C-w
toggle read-only status of buffer C-x C-q

Getting Help

The help system is simple. Type C-h (or F1) and follow the directions. If you are a first-time user, type C-h t for a tutorial.

remove help window C-x 1
scroll help window C-M-v
apropos: show commands matching a string C-h a
describe the function a key runs C-h k
describe a function C-h f
get mode-specific information C-h m

Error Recovery

abort partially typed or executing command C-g
recover files lost by a system crash M-x recover-session
undo an unwanted change C-x u, C-_ or C-/
restore a buffer to its original contents M-x revert-buffer
redraw garbled screen C-l

Incremental Search

search forward C-s
search backward C-r
regular expression search C-M-s
reverse regular expression search C-M-r

in i-search mode:

select previous search string M-p
select next later search string M-n
exit incremental search RET
undo effect of last character DEL
abort current search C-g

Use C-s or C-r again to repeat the search in either direction. If Emacs is still searching, C-g cancels only the part not done.

Motion

entity to move over backward forward
character C-b C-f
word M-b M-f
line C-p C-n
goto line beginning (or end) C-a C-e
sentence M-a M-e
paragraph M-{ M-}
page C-x [ C-x ]
sexp (balanced expression) C-M-b C-M-f
function C-M-a C-M-e
goto buffer beginning (or end) M-< M->
scroll to next screen C-v
scroll to previous screen M-v
scroll left C-x <
scroll right C-x >
scroll current line to center of screen C-u C-l

Kill and Deleting

entity to kill backward forward
character (delete, not kill) DEL C-d
word M-DEL M-d
line (to end of) M-0 C-k C-k
sentence C-x DEL M-k
sexp (balanced expression) M— C-M-k C-M-k
kill region C-w
copy region to kill ring M-w
kill through next occurrence of char M-z char
yank back last thing kill C-y
replace last yank with previous kill M-y

Marking

set mark here C-@ or C-SPC
exchange point and mark C-x C-x
set mark arg words away M-@
mark paragraph M-h
mark page C-x C-p
mark sexp C-M-@
mark function C-x h

Query Replace

interactively replace a text string M-%
using regular expressions M-x query-replace-regexp

Valid responses in query-replace mode are:

replace this one, go on to next SPC
replace this one, don't move ,
skip to next without replacing DEL
replace all remaining matches !
back up to previous match ^
exit query-replace RET
enter recursive edit (C-M-c to exit) C-r

Multiple Windows

When two commands are shown, the second one is a similar command for a frame instead of a window.

delete all other windows C-x 1 C-x 5 1
split window, above and below C-x 2 C-x 5 2
delete this window C-x 0 C-x 5 0
split window, side by side C-x 3
scroll other window C-M-v
switch cursor to other window C-x o C-x 5 o
select buffer in other window C-x 4 b C-x 5 b
display buffer in other window C-x 4 C-o C-x 5 C-o
find file in other window C-x 4 f C-x 5 f
find file read-only in other window C-x 4 r C-x 5 r
run Dired in other window C-x 4 d C-x 5 d
find tag in other window C-x 4 . C-x 5 .
grow window taller C-x ^
shrink window narrower C-x {
grow window wider C-x }

Formatting

indent current line (mode-dependent) TAB
indent region (mode-dependent) C-M-\
indent sexp (mode-dependent) C-M-q
indent region rigidly arg columns C-x TAB
insert newline after point C-o
move rest of line vertically down C-M-o
delete blank lines around point C-x C-o
join line with previous (with arg, next) M-^
delete all white space around point M-\
put exactly one space at point M-SPC
fill paragraph M-q
set fill column C-x f
set prefix each line starts with C-x .
set face M-o

Case Change

uppercase word M-u
lowercase word M-l
capitalize word M-c
uppercase region C-x C-u
lowercase region C-x C-l

The Minibuffer

The following keys are defined in the minibuffer.

complete as much as possible TAB
complete up to one word SPC
complete and execute RET
show possible completions ?
fetch previous minibuffer input M-p
fetch next minibuffer input or default M-n
regexp search backward through history M-r
regexp search forward through history M-s
abort command C-g

Type C-x ESC ESC or C-x M-: to edit and repeat the last command that used in the minibuffer. Type F10 to active the menu bar using the minibuffer.

Buffers

select another buffer C-x b
list all buffers C-x C-b
kill a buffer C-x k

Transposing

transpose characters C-t
transpose words M-t
transpose lines C-x C-t
transpose sexps C-M-t

Spelling Check

check spelling of current word M-$
check spelling of all words in region M-x ispell-region
check spelling of entire buffer M-x ispell-buffer

Tags

find a tag (a definition) M-.
find next occurrence of tag C-u M-.
specify a new tags file M-x visit-tags-table
regexp search on all files in tags table M-x tags-search
run query-replace on all the files M-x tags-query-replace
continue last tags search or query-replace M-,

Shells

execute a shell command M-!
run a shell command on the region M-|
filter region through a shell command C-u M-|
start a shell command in window \*shell\* M-x shell

Rectangles

copy rectangle to register C-x r r
kill rectangle C-x r k
yank rectangle C-x r y
open rectangle, shifting text right C-x r o
blank out rectangle C-x r c
prefix each line with a string C-x r t

Abbrevs

add global abbrev C-x a g
add mode-local abbrev C-x a l
add global expansion for this abbrev C-x a i g
add mode-local expansion for this abbrev C-x a i l
explicitly expand abbrev C-x a e
expand previous word dynamically M-/

Regular Expressions

any single character except a newline . (dot)
zero or more repeats *
one or more repeats +
zero or one repeat ?
quote regular expression special character \c
alternative ("or") \|
grouping \( ... \)
same text as nth group \n
at word break \b
not at word break \B
entity match start match end
line ^ $
word \< \>
buffer \` \'
class of characters match these match others
explicit set [ ... ] [^ ... ]
word-syntax character \w \W
character with syntax c \sc \Sc

International Character Sets

specify principal language C-x RET l
show all input methods M-x list-input-methods
enable or disable input method C-\
set coding system for next command C-x RET c
show all coding systems M-x list-coding-systems
choose preferred coding system M-x prefer-coding-system

Info

enter the Info documentation reader C-h i
find specified function or variable in Info C-h S

Moving within a node:

scroll forward SPC
scroll reverse DEL
beginning of node . (dot)

Moving between nodes:

next node n
previous node p
move up u
select menu item by name m
select nth menu item by number (1-9) n
follow cross reference (return with l) f
return to last node you saw l
return to directory node d
go to top node of Info file t
go to any node by name g

Other:

run Info tutorial h
quit Info q
search nodes for regexp M-s

Registers

save region into register C-x r s
insert register contents into buffer C-x r i
save value of point in register C-x r SPC
jump to point saved in register C-x r j

Keyboard Macros

start defining a keyboard macro C-x (
end keyboard macro definition C-x )
execute last-defined keyboard macro C-x e
append to last keyboard macro C-u C-x (
name last keyboard macro M-x name-last-kbd-macro
insert Lisp definition in buffer M-x insert-kbd-macro

Commands dealing with Emacs Lisp

eval sexp before point C-x C-e
eval current defun C-M-x
eval region M-x eval-region
read and eval minibuffer M-:
load from standard system directory M-x load-library

Simple Customization

customize variables and faces M-x customize

Making global key bindings in Emacs Lisp (examples):

(global-set-key "\C-cg" 'goto-line)
(global-set-key "\M-#" 'query-replace-regexp)

Writing Commands

(defun command-name (args)
"documentation"
(interactive "template")
body
)

An example:

(defun this-line-to-top-of-window (line)
"Reposition line point is on to top of window.
With ARG, put point on line ARG."
(interactive "P")
(recenter (if (null line)
0
(prefix-numeric-value line))))

The interactive spec says how to read arguments interactively. Type C-h f interactive for more details.


Copyright (c) 2005 Free Software Foundation, Inc. v2.3 for GNU Emacs 22, 2005 designed by Stephen Gildea.

Permission is granted to make and distribute copies of this card provided the copyright notice and this permission notice are preserved on all copies.

For copies of GNU Emacs manual, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA



Emacs 22 Released

Finally...

Thursday, May 17, 2007

Unicad 0.65

Unicad.el FAQ


project address: http://code.google.com/p/unicad/

What is Unicad?

Unicad is short for Universal Charset Auto Detector. It is an Emacs-Lisp port of Mozilla Universal Charset Detector.

What can Unicad do?

Unicad helps Emacs to guess the correct coding system when opening a file.

What languages and coding systems does Unicad support?

  • Chinese Simplified (gb18030, gbk, gb2312, hz-gb-2312, iso-2022-cn)
  • Chinese Triditional (big5, gb18030, gbk, euc-tw)
  • Japanese (sjis, euc-jp, iso-2022-jp)
  • Korean (euc-kr, iso-2022-kr)
  • Greek (iso-8859-7, windows-1253)
  • Russian (iso-8859-5, windows-1251, koi8-r, ibm855)
  • Bulgarian (iso-8859-5, windows-1251)
  • Western European (latin-1)
  • Central European (latin-2)

Who should use Unicad?

1. Emacs Users. Unicad is an Emacs extension that written in Elisp. It is designed and works for Emacs.

2. Multilanguage Users. If you are English only speakers, then there is no need to install Unicad on Emacs. Otherwise, if you need to read and edit files in multiple language and use different coding systems, Unicad will definitely help you in recognizing coding systems.

3. Anyone who is tired of struggling with garbled text. Normal Text Editors are not so intelligent to choose correct coding system among various and complicated charsets. I suggest you try the most powerful text editor ever in the world - Emacs and Unicad.

How to use Unicad?

Download the latest unicad.el, copy it to your Emacs load path (e.g. site-lisp directory), and add the following line to your ~/.emacs:

(require 'unicad)

You may byte compile this file to speed up the charset detecting process.

What's the difference between Unicad and Mozilla Universal Charset Detector?

  • optimized for detecting shorter text files.
  • add support for Central European Languages, which use iso-8859-2 coding system.
  • add support for Traditional Chinese that uses gbk coding system.
  • add support for single byte only katakana that uses sjis coding system.


Thursday, May 10, 2007

为什么我偏爱 Emacs

为什么我偏爱 Emacs

在Windows下我通常只使用 Emacs (NTEmacs),用TotalCommander的F3快速查看文 件;在Linux下也基本用 Emacs,用 Vim 修改单个文件。Emacs和一般编辑器相比 到底有什么优点呢?尤其是和UltraEdit,EditPlus等等这样的所谓主流的Win32编辑器相比。

免费并且开源

虽然盗版满天飞,但是如果是工作的人用盗版软件做和工作相关的开发任务还是 不合适的。

全定制

包括外观,配色,字体,不同的中英文字体,编码,模式,快捷键,自建函数等 等一切都是可定制的,这种自由感是在win32软件里体会不到的。

解放鼠标

在噼里啪啦码字的过程中,如果还有伸手去找鼠标是很不爽的事。既然不需要鼠 标了,菜单栏,工具栏这些也都不需要了,这样可以同时扩大可视面积。在分辨 率有限的情况下看到更多有用的信息。

随意分割窗口

在 Emacs 里,可以任意分割窗口,可以水平分割,可以垂直分割,可以先水平分 割再垂直分割。还可以在2个或更多的窗口中看同一个文件。这对于编辑长文件是 很有用的,经常需要看同一个文件不同部分。

更好的选定方式

在 Win32 软件里,选定区域是一种连续的操作,稍不当心就得重新选过,如果 区域开头差了一个字,又得重新选了。

在 Emacs 里的 mark 完全是一种全新的体验。在定好 mark 头之后可以用各种 方式移动,比如用 isearch 来更快的定位。还可以用 C-x C-x 交换 mark 和 point 的位置,调整选定的区域。

在你进行了复制或者调整缩进的操作之后,还可以用 C-x C-x 再次高亮前一次 选中的区域。

列操作

我总是不能理解为什么老有人说UE的列操作多么优秀,却不见有什么例子以显示 哪些列操作是UE独有的。事实上我就觉得 Emacs 的列操作要方便得多。Emacs里 面根本不需要特殊的列模式。你可以像往常一样选中区域然后用列复制,列删除 等等命令就可以了。

dired 模式

可以把它看作一个 Emacs 文件管理器,在 dired-mode 里浏览文件,打开文件, 新建文件夹,改名等等。说起修改文件名,在 dired 里使用 wdired 配合列操作, 宏,正则表达式,这恐怕最方便的批处理改名软件了。比如一个文件夹里有20集 TV,名字是 Friends - s02e01 - TOW xxxx.avi 之类的,然后又从别处下载了 40个字幕文件,文件名是 0201.en.srt 0201.cn.srt 之类的,如何把字幕文件名 改为和相应的视频文件名呢?难道一个一个复制粘贴?如果有10季一共两百多集 怎么办?这时候宏和列操作就是最方便的了。只要定义一次宏,然后运行20次就 搞定了。切身体验,我觉得比Totalcommand 的批处理重命名还要好用。UE里面有 吗?

Do What I Mean (dwim)

这是个很有意思的功能,Emacs 会自动猜测你想要做什么,用一个命令,或者一个快捷键就能完成好多操作。比如 comment-dwim (M-;),在代码中如果没有选中区域,就是在这一行后面加上注释;如果选中一块区域,就会注释一块区域;如果选中的这块区域已经都是注释了,那就是反注释这块区域。

集成 shell

M-x eshell 可以启动 Emacs shell,方便的调试程序,运行脚本,文件管理等 等 command line 能做的事。

相关链接:

Monday, March 26, 2007

Test from Emacs




This is a post from g-client, an Emacs client for Google Service.
Here is the website for g-client.

Monday, March 19, 2007

curl and xsltproc for cygwin

for curl under cygwin you need to install curl and libcurl3, which could be found in any cygwin ftp mirror.
For example:
http://ftp.uni-kl.de/pub/cygwin/release/curl/
unpack the tarballs to cygwin bin directory. done.

for xsltproc you need to install xmlsec, xsldbg, libxslt and libxml, which can be found here:
http://www.zlatkovic.com/libxml.en.html

Tuesday, March 06, 2007

FVWM-Crystal

I have tried some window managers these days, such as Beryl and FVWM. The 3D effect of Beryl is really astonishing but its requirement is too high. Finally I found fvwm-crystal. It is both nice looking and light-weighted. I like it.

However, I found the fvwm-crystal project is not well documented. Here are some tips for the configuration of fvwm-crystal.

* fvwm-crystal is actually a nice configuration of fvwm with some handy small tools. So almost all the configuration for fvwm can be used directly on fvwm-crystal.

* The user configuration file is stored in ~/.fvwm-crystal/userconfig (for fvwm-crystal 3.0.4 and above). The configuration file for fvwm-crystal 3.0.3 and below is still in ~/.fvwm/ .

* The most default key bindings are Meta- or Meta-Shift- which conflict with Emacs key bindings. So I have to disable them all like this:
Key 1 A MS - # disable M-S-1
Key X A M - # disable M-x

The default key bindings are in /usr/local/share/fvwm-crystal/fvwm/components/bindings/ .

* Font set. The default font is Verdana. So the multibyte characters are not able to be displayed correctly. I have to change it to font like Vera Sans YuanTi. The window title bar font configuration is:
Style * Font "Shadow=1 1:StringEncoding=gbk-0:xft:Vera Sans YuanTi:Bold:pixelsize=12:minspace=True:encoding=iso10646-1"

* I think 8 virtual desktops are too many. So change it to 6:
DeskTopSize 6x1

* The "suspend" in the main menu doesn't work quite well. It will logout and then suspend to memory. I use Fn+F4 on my ThinkPad instead. This works fine. Maybe you need to install xscreensaver.

* Removable devices can't be auto mounted as in GNOME. You can install ivman and put the following line into ~/.bashrc:
ivman --nofork > /dev/null 2>&1 &
Here is some more information about how to auto mount removable devices.

* KDE applications such as Amarok and Kopete don't stay in trayer. You may need to start Amarok this way:
amarok
dcop kded kded loadModule kdetrayproxy
After that, other kde apps like Kopete will stay in trayer as well. However, I have tried to put the second line in to InitFunction or StartFunction but it doesn't work.

* Some startup applications. You can add startup apps like this:
AddToFunc InitFunction
+ I Exec exec dcop kded kded loadModule kdetrayproxy
+ I Test (x gkrellm) Exec pidof gkrellm || exec gkrellm
+ I Test (x update-notifier) Exec exec update-notifier
+ I Test (x gdeskcal) X gdeskcal

***

Monday, February 12, 2007

unicad.el

Emacs文件编码识别,解决乱码问题

unicad project is now hosted on Google Code: http://code.google.com/p/unicad/

The latest unicad.el can be find in the download list.

I would like to introduce unicad.el, a Universal charset auto detector for GNU Emacs.

If you have to deal text files in multi language (Chinese, Japanese, Russian, German or Polish) or have the experience of reading a garbled text file or being confused to choose a correct encoding, this unicad.el is here for you. It can tell (or guess) which coding-system is most probably for a plain text file. It's very easy to use unicad.el. Simply download and copy this file to your emacs loading path (like "site-lisp"), add following lines to your ~/.emacs:
(require 'unicad)
done.

It's supposed that the coding detection process will not interfere your regular edit tasks. If you found the speed of find-file is slowed down, you'd better byte-compile this file.

Hope you'll enjoy it.

Download page of unicad.el.