Liuw's Thinkpad

想要赢就先学会输,想要成功就先学会失败

Archive for the ‘emacs’ tag

Org-mode使用笔记

with 3 comments

Org-mode使用笔记
================

Author: liuw
Date: 2010-02-25 Thu.

Table of Contents
=================
1 介绍
2 具体配置
2.1 dotemacs中的org-mode配置
2.2 org文件中的配置
3 Org-mode作弊条
4 更多

1 介绍
~~~~~~~

用Emacs的时间也不短了,但是也仅限限于写写程序,作为一个很纯粹的编辑器来使用。我知道Emacs还有很多其他的功能,但是自己却懒得学。好吧,我确实是一个懒人,自己觉得事情老是做不完,又健忘,所以很多时候,必须有小纸条。

后来发现好东西了,就是Emacs的org-mode。虽然也不是第一次听说它了,但是一直懒得学。现在觉得是时间改一改坏习惯了,所以就打算用org-mode来把自己的时间管理起来。老外这方面的文章不少,把org-mode和GTD方法结合起来,作为自己的时间和日程管理工具。中文也有点资料,但是不多。这里就随便记一下自己的一些设置吧。

2 具体配置
~~~~~~~~~~~

2.1 dotemacs中的org-mode配置
=============================

除使用org-mode作为org文件的默认模式之外,也把它作为txt文件的默认模式(因为实在是太好用了)。另外还定义了一些全局的快捷键,可以更快地使用一些功能。

打开org-log-done,这样一个TODO处理完之后,会自动标记上CLOSED这样的语句,并且记录当时的时间。

另外,TODO keywords使用的是GTD风格的keyword。这样对于某一个TODO的执行情况可以进行更好的跟踪。

我喜欢把我的TODO分布到几个文件中去,这样在agenda看的时候,比较清楚点。更进一步的,我使用git把这些org文件进行统一的管理。当然,org-mode也有archive的功能,但是我目前还没有启用。

(add-to-list 'auto-mode-alist '("\.\(org\|org_archive\|txt\)$" . org-mode))
(define-key global-map "C-cl" 'org-store-link)
(define-key global-map "C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-hide-leading-stars t)

(setq org-todo-keywords
      (list "TODO(t)" "STARTED(s!)" "WAITING(w@)" "|" "CANCELED(c)" "DONE(d)"))
(setq org-agenda-files
      (list "~/git/org/personal.org"
            "~/git/org/lab.org"
            "~/git/org/opensource.org"
            "~/git/org/todo.org"))
(defun todo ()
  (interactive)
  (find-file "~/git/org/todo.org")
  )

2.2 org文件中的配置
====================

org-mode也支持per-file-variable,所以可以对每个文件进行单独的配置。由于我使用类GTD的方法进行管理,所以我在每个文件中都加上类似的标签配置。

#+TAGS: @work(w) @home(h) @sport(s)
#+TAGS: laptop(l) pc(p)

这些标签用于标示GTD中的context概念。

3 Org-mode作弊条
~~~~~~~~~~~~~~~~~

  快捷键          功能

  C-c a           agenda模式
  C-c C-s         设置schedule时间
  C-c C-d         设置deadline时间
  C-c C-t         设置事务状态
  C-c C-c         设置标签
  C-c ,           设置优先级
  S-/   改变优先级

4 更多
~~~~~~~

Org-mode的强大之处是,它可以为你自动生成图形、表格(在表格中甚至还支持计算)。可以把org文件导出成为各种各样的格式。

目前我使用的功能已经足够了,本着能少学就少学的精神,很多东西还没有进行深究。有需要再看info去。

这个文件就是用org-mode的publishing功能生成了。原先写的是一个txt文件,呵呵。挺不错的。

org-mode

Written by liuw

February 25th, 2010 at 3:54 pm

Posted in 分享,生活

Tagged with ,

Elisp不支持闭包,白忙了

without comments

今天下午研究了一下Continuation,在Wikipedia上看到了Continuation Passing Style的相关介绍,带有例程(不过是用Scheme写的)。既然自己在用Emacs,那么试试把例子都用Elisp实现一下吧。

其中有一个函数,用来制作支持CPS的函数,原型是这样的:

(define (cps-prim f)
  (lambda args
    (let ((r (reverse args)))
      ((car r) (apply f
                (reverse (cdr r)))))))

这样用,比如说要制作一个支持CPS的减法运算:

(define cps- (cps-prim -))

假如不使用cps-prim,那么每个函数都要这样写:

(define cps- (a b k)
  (k (- a b)))

很显然,使用cps-prim更加方便点。于是我打算用Elisp也做一个同样的函数,谁让我这么懒呢。

Elisp比较乱,所以写了挺久的,但是总算是写出来了:

(defun cps-prim (f)
  #'(lambda (args)
      (let ((r (reverse args)))
        (funcall (car r) (apply f
                                (reverse (cdr r)))))))
(fset 'cps- (cps-prim '-))

但是使用cps-的时候,会提示f无值。好吧,查一个info,心彻底凉了。11.9.2中明确写到,Elisp是不支持闭包的,所以f在cps-中是unbound的。想偷懒偷不成咯。

再进一步想想,Elisp不支持闭包,是否就不支持高阶函数呢?个人程序设计语言方面没什么了解,只能google了。显然我不是第一个想到这个问题的,还真是发现了一些有趣的东西。

http://lambda-the-ultimate.org/node/1936

有人说:

Closure = Function x Environment

不得不说,这个等式,比一个冗长的定义更清楚。

Written by liuw

January 23rd, 2010 at 10:42 pm

What If You Need Hint for Certain Keywords

without comments

When editing in Emacs, sometimes it’s necessary to search for certain commands, when you only know part of the command or only have one or two keywords as clue.

M-x apropos

Written by liuw

January 18th, 2010 at 4:32 pm

Posted in UNIX-like,分享

Tagged with ,

Fast Configuration of Company Mode

without comments

http://nschum.de/src/emacs/company-mode/

Add following lines to dotemacs.

(add-to-list 'load-path "/path/to/company")
(autoload 'company-mode "company" nil t)

;; Add hook for file types.
(add-hook 'c-mode-hook (lambda() (company-mode)))

;; Bind company-manual-begin, company-complete-common, company-complete,
;; company-select-next to a key in the global map.
(global-set-key "\t" 'company-complete-common)
;; Alternatively, set company-idle-delay to t, so it will complete immediately.

;; Helper functions
  (defun complete-or-indent ()
    (interactive)
    (if (company-manual-begin)
        (company-complete-common)
      (indent-according-to-mode)))
  (defun indent-or-complete ()
    (interactive)
    (if (looking-at "\\_>")
        (company-complete-common)
      (indent-according-to-mode)))

Since I would like to use TAB for both completion and indentation, I prefer the following helper function to make life easier – company will mess up TAB key when in minibuffer.

(defun tab-complete-or-indent ()
  (interactive)
  (if (minibufferp)
      (minibuffer-complete)
    (if (company-manual-begin)
        (company-complete-common)
      (indent-according-to-mode))
    )
  )

(global-set-key [tab] 'tab-complete-or-indent)

Currently, I’m using the following configuration.

(add-hook 'c-mode-hook (lambda() (company-mode)))
(add-hook 'lisp-mode-hook (lambda() (company-mode)))
(add-hook 'emacs-lisp-mode-hook (lambda() (company-mode)))

(setq company-begin-commands '(self-insert-command))
(setq company-idle-delay t)
(setq company-minimum-prefix-length 1)

Written by liuw

January 12th, 2010 at 7:38 pm

Posted in UNIX-like,分享

Tagged with ,

Emacs Local Variables

without comments

目前使用的C程序local variables如下:

/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */

关于Emacs的local variables,可以参考Emacs的info和下面的网页。

http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html

Written by liuw

December 7th, 2009 at 3:34 pm

Bash/VIM/EMACS中输入特殊字符

without comments

有时用VIM打开一个文本文件,可以看到有的行结尾是^M来结束的,很不美观。在进行替换的时候,这个^M(还有一些其他类似的字符)是不能以一个^加一个M的形式进行输入的,因为它本身是一个字符。

在Bash和VIM中,可以以C-v C-m的形式去输入^M,其他的一些特殊字符也是同理的。

而在EMACS中,C-v已经有所用了,显然就不是用C-v C-m来做了。想起来以前是怎么输入TAB的,小试验一下,成了。实际就是调用quoted-insert这个函数去完成的。按键是C-q C-m。

Written by liuw

November 30th, 2009 at 8:47 pm

Posted in UNIX-like,分享

Tagged with , ,

EmacsWiki上的Ctrl调整技巧

without comments

http://www.emacswiki.org/emacs/MovingTheCtrlKey

其中有一个console下调整的技巧(xmodmap只能在有X的情况下使用)。

keymaps 0-63
keycode 58 = Control
keycode 29 = Caps_Lock
alt_is_meta

然后用loadkeys(1)加载。

Written by liuw

October 15th, 2009 at 4:49 pm

Posted in 分享

Tagged with , ,

Emacs Notes

without comments

This is an abstract from the Emacs manual, in case I forget those somewhat weird keybindings.

Movement

`C-M-v’ `C-M-V’
Scroll the other window.

Setting the Mark

`C-SPC’
Set the mark at point (`set-mark-command’).

`C-@’
The same.

We can also use mouse to accomplish the task.

Operating on the Region

`C-w’
Kill it.

`C-x x’
Save it in a register.

`C-x C-l’ `C-x C-u’
Convert case.

`C-x TAB’ `C-M-\’
Indent region.

Other

`C-y’
Yank. Followed by `M-y’ travels through the killing ring.

`C-u’
Feed argument to other commands.

`C-s C-w’
Search word under cursor.

Written by liuw

October 6th, 2009 at 11:41 pm

Posted in Programming,UNIX-like

Tagged with ,

Switch Left Ctrl and Capslock

without comments

I use ctrl key often, because I am fond of doing editing in EMACS. I use it so often that my hands finally don’t agree with me. I start to get pain in my little finger and my wrist.

I’ve always been fansinating with the MAC, because it’s keyboard layout is compatible with the original UNIX style. I am using Windows XP with a standard keyboard layout, so I did some search to see whether there is a way to configure my layout. Luckily, I found one.

Open `regedit’, then go to `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout’. Make a new binary type named `Scancode map’, which contains following content.

 0000: 00 00 00 00 00 00 00 00
 0008: 03 00 00 00 3A 00 1D 00
 0010: 1D 00 3A 00 00 00 00 00

Logout and login, ctrl and capslock are switched.

Written by liuw

September 26th, 2009 at 8:18 pm

Posted in 分享

Tagged with , ,

Emacs Hexl Mode

without comments

打开文件
M-x hexl-find-file

修改一个byte
C-M-x

输入串
hexl-insert-hex-string

其他
hexl-insert-decimal-char
hexl-insert-hex-char
hexl-insert-octal-char

虽然远远比不上WinHex,但是毕竟是可以用了。

Written by liuw

August 7th, 2009 at 9:21 am

Posted in Programming,UNIX-like

Tagged with , , ,