ubuntu 10.10
emacs23
之前一直用vim,老感觉ESC键让我很难受,总是要跨越那么远去按,于是想用emacs,先把emacs装起来。
apt-get install emacs
哦拉,最起码可以看文本,代码了。然后看代码,没有行号,我郁闷了。在网上找到方法解决,如下:
下载linum.el
我的内容如下,你也可以自己去网上下一个:
;;; linum.el --- Display line numbers to the left of buffers
;; Copyright (C) 2007, 2008 Markus Triska
;; Author: Markus Triska <markus.triska@gmx.at>
;; Keywords: convenience
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Display line numbers for the current buffer. Copy linum.el to your
;; load-path and add to your .emacs:
;; (require 'linum)
;; Then toggle display of line numbers with M-x linum-mode. To enable
;; line numbering in all buffers, use M-x global-linum-mode.
;;; Code:
(defconst linum-version "0.9wza")
(defvar linum-overlays nil "Overlays used in this buffer.")
(defvar linum-available nil "Overlays available for reuse.")
(defvar linum-before-numbering-hook nil
"Functions run in each buffer before line numbering starts.")
(mapc #'make-variable-buffer-local '(linum-overlays linum-available))
(defgroup linum nil
"Show line numbers to the left of buffers"
:group 'convenience)
;;;###autoload
(defcustom linum-format 'dynamic
"Format used to display line numbers. Either a format string
like \"%7d\", 'dynamic to adapt the width as needed, or a
function that is called with a line number as its argument and
should evaluate to a string to be shown on that line. See also
`linum-before-numbering-hook'."
:group 'linum
:type 'sexp)
(defface linum
'((t :inherit (shadow default)))
"Face for displaying line numbers in the display margin."
:group 'linum)
(defcustom linum-eager t
"Whether line numbers should be updated after each command.
The conservative setting `nil' might miss some buffer changes,
and you have to scroll or press C-l to update the numbers."
:group 'linum
:type 'boolean)
(defcustom linum-delay nil
"Delay updates to give Emacs a chance for other changes."
:group 'linum
:type 'boolean)
;;;###autoload
(define-minor-mode linum-mode
"Toggle display of line numbers in the left marginal area."
:lighter "" ; for desktop.el
(if linum-mode
(progn
(if linum-eager
(add-hook 'post-command-hook (if linum-delay
'linum-schedule
'linum-update-current) nil t)
(add-hook 'after-change-functions 'linum-after-change nil t))
(add-hook 'window-scroll-functions 'linum-after-scroll nil t)
;; mistake in Emacs: window-size-change-functions cannot be local
(add-hook 'window-size-change-functions 'linum-after-size)
(add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
(add-hook 'window-configuration-change-hook
'linum-after-config nil t)
(linum-update-current))
(remove-hook 'post-command-hook 'linum-update-current t)
(remove-hook 'post-command-hook 'linum-schedule t)
(remove-hook 'window-size-change-functions 'linum-after-size)
(remove-hook 'window-scroll-functions 'linum-after-scroll t)
(remove-hook 'after-change-functions 'linum-after-change t)
(remove-hook 'window-configuration-change-hook 'linum-after-config t)
(remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
(linum-delete-overlays)))
;;;###autoload
(define-globalized-minor-mode global-linum-mode linum-mode linum-on)
(defun linum-on ()
(unless (minibufferp)
(linum-mode 1)))
(defun linum-delete-overlays ()
"Delete all overlays displaying line numbers for this buffer."
(mapc #'delete-overlay linum-overlays)
(setq linum-overlays nil)
(dolist (w (get-buffer-window-list (current-buffer) nil t))
(set-window-margins w 0)))
(defun linum-update-current ()
"Update line numbers for the current buffer."
(linum-update (current-buffer)))
(defun linum-update (buffer)
"Update line numbers for all windows displaying BUFFER."
(with-current-buffer buffer
(when linum-mode
(setq linum-available linum-overlays)
(setq linum-overlays nil)
(save-excursion
(mapc #'linum-update-window
(get-buffer-window-list buffer nil 'visible)))
(mapc #'delete-overlay linum-available)
(setq linum-available nil))))
(defun linum-update-window (win)
"Update line numbers for the portion visible in window WIN."
(goto-char (window-start win))
(let ((line (line-number-at-pos))
(limit (window-end win t))
(fmt (cond ((stringp linum-format) linum-format)
((eq linum-format 'dynamic)
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "d")))))
(width 0))
(run-hooks 'linum-before-numbering-hook)
;; Create an overlay (or reuse an existing one) for each
;; line visible in this window, if necessary.
(while (and (not (eobp)) (<= (point) limit))
(let* ((str (if fmt
(propertize (format fmt line) 'face 'linum)
(funcall linum-format line)))
(visited (catch 'visited
(dolist (o (overlays-in (point) (point)))
(when (string= (overlay-get o 'linum-str) str)
(unless (memq o linum-overlays)
(push o linum-overlays))
(setq linum-available (delete o linum-available))
(throw 'visited t))))))
(setq width (max width (length str)))
(unless visited
(let ((ov (if (null linum-available)
(make-overlay (point) (point))
(move-overlay (pop linum-available) (point) (point)))))
(push ov linum-overlays)
(overlay-put ov 'before-string
(propertize " " 'display `((margin left-margin) ,str)))
(overlay-put ov 'linum-str str))))
(forward-line)
(setq line (1+ line)))
(set-window-margins win width)))
(defun linum-after-change (beg end len)
;; update overlays on deletions, and after newlines are inserted
(when (or (= beg end)
(= end (point-max))
;; TODO: use string-match-p with CVS or new release
(string-match "\n" (buffer-substring-no-properties beg end)))
(linum-update-current)))
(defun linum-after-scroll (win start)
(linum-update (window-buffer win)))
(defun linum-after-size (frame)
(linum-after-config))
(defun linum-schedule ()
;; schedule an update; the delay gives Emacs a chance for display changes
(run-with-idle-timer 0 nil #'linum-update-current))
(defun linum-after-config ()
(walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible))
(provide 'linum)
;;; linum.el ends here
你可以拷贝下来直接命名为linum.el。
我把linum.el放在~/.emacs.d/package/目录下,~/.emacs配置如下:
;; 显示行号
(add-to-list 'load-path "~/.emacs.d/package")
(load "linum.el")
(require 'linum)
(global-linum-mode 1)
这样就可以显示行号了,哈哈,第一步成功,虽然我不知道add-to-list,load-path的意思,以后再学吧。
然后我发现用emacs录入.emacs文件的时候,我打不了中文,对,就是那个注释,我又蛋疼了,没有中文输入我用个屁阿,上网查吧。
我本来用的是scim,感觉还是满好用的。
scim安装越来越简单了,我原来空白机子上装的时候就两步:
apt-get install scim
然后就只要在/etc/X11/Xsession.d/目录下加一个文件,95xinput,写入如下内容就行了:
/usr/bin/scim -d
XMODIFIERS="@im=SCIM"
export XMODIFIERS
export GTK_IM_MODULE=scim
简单的一笔阿,但是后来我发现我错了。
emacs不能直接调用scim,找了半天都没有解决,继续找,终于找到一个scim-bridge,在wiki上找到的,所以用linux还得经常去这些网站阿,我直接把我看到的内容贴出来:
ScimBridge Chinese
scim-bridge.el 是 GNU Emacs 里面的 SCIM-Bridge 客户端. (EnglishVersion)
scim-bridge.el 可以保存不同缓存里面的输入状态, 这样你可以在 Emacs 里快速的输入中文, 而不用反复的切换全局的输入状态, 非常方便.
Contents
1. 什么是 SCIM?
2. 安装
3. 自定义
4. 截图
什么是 SCIM?
SCIM 是一个通用的智能输入法平台 (支持 中文, 日文, 韩文和许多欧洲语言), 可以使用在 POSIX 风格的操作系统, 包括 Linux 和 BSD.
安装
* 安装 SCIM:
o 在 Debian 里, 步骤非常简单:
sudo aptitude install scim scim-bridge-agent scim-bridge-client-gtk scim-bridge-client-qt4 scim-qtimm -y
o 你还可以使用下列命令来安装"拼音输入法”:
sudo aptitude install scim-pinyin -y
* 安装 scim-bridge.el:
o 从 scim-bridge.el project in Launchpad 里下载最新的压缩包.
o 让 Emacs 禁用 XIM:
+ 加入以下的命令到 ~/.Xresources:
Emacs*useXIM: false
+ 然后执行下列命令生效:
xrdb ~/.Xresources
o 加入 scim-bridge.el 到 load-path:
+ 解压 scim-bridge 的压缩包并放在 “~/elisp” 目录下, 然后添加下列命令到 ~/.emacs:
(add-to-list 'load-path (expand-file-name "~/elisp"))
o 修改 SCIM 的切换键:
+ 应为 Ctrl-Space 按键被Emacs默认绑定了, 所以要在 SCIM 图形设置界面里添加其他的按键, 比如 Super-Space (其他任意键也可以).
o 加载并设置 scim-bridge.el:
+ 加入下列到 ~/.emacs:
;; 加载.
(require 'scim-bridge-zh-si)
;;; 如果你使用繁体中文, 用 (require 'scim-bridge-zh-tr) 替换.
;; 加载 ~/.emacs 后自动开启 scim-mode.
(add-hook 'after-init-hook 'scim-mode-on)
;; 设置输入法切换键
(scim-define-common-key (kbd "s-SPC") t)
;; 使用 C-SPC 用作标记命令.
(scim-define-common-key (kbd "C-SPC") nil)
;; 使用 C-/ 用作撤销命令.
(scim-define-common-key (kbd "C-\\") nil)
;; 设置不同输入状态下光标颜色.
(setq scim-cursor-color '("red" "blue" "limegreen"))
现在按一下 Suepr-Space, 开始输入中文吧。
自定义
* 你可以通过下列方法自定义 scim-bridge.el:
M-x customize-group RET scim-bridge RET
我已经把相关的文档翻译成简体中文和繁体中文, enjoy!
我一步步照作,就是scim的切换键换成了shift-space,其他一模一样,然后打开emacs,就可以切换输入法了。之前用那些什么LC_CTYPE=zh_CN.UTF-8 emacs,可以弹出scim,结果只有英文的,我奶奶的,弹了比没弹出更让我蛋疼。
话说,我这时已经可以弹出scim那个框了,而且那个框中确实有智能拼音四个字,我郁闷的发现,我仍然只能输入中文,我的天呢,还让不让人活阿。
我继续找方法,发现网上没这种情况阿,我公司自己的机子好多网是不能上的,我们用的是远程客户端。无意间,我用本机的firefox查询的时候(我一般不用本机上网),发现我打不进中文,我知道了,不是emacs的问题,是我的scim出问题了,之前网上看到有人说用ibus可以在emacs中输入中文,我当时把scim删了,装了一个ibus,发现不好用,而且ibus-el在我们有限的网络上也找不到,就把ibus又删了,重装会scim,我差点背叛了它,可是最终还是回来了,这时候有个问题,我不知道要装scim-pinyin阿,第一次装的时候都是默认帮我把这个包装在上面的,可是这次他不帮我装了,发现了这个问题,我终于搞定了。
scim没问题了,emacs也好了,我的emacs征程要开始了。
emacs23
之前一直用vim,老感觉ESC键让我很难受,总是要跨越那么远去按,于是想用emacs,先把emacs装起来。
apt-get install emacs
哦拉,最起码可以看文本,代码了。然后看代码,没有行号,我郁闷了。在网上找到方法解决,如下:
下载linum.el
我的内容如下,你也可以自己去网上下一个:
;;; linum.el --- Display line numbers to the left of buffers
;; Copyright (C) 2007, 2008 Markus Triska
;; Author: Markus Triska <markus.triska@gmx.at>
;; Keywords: convenience
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Display line numbers for the current buffer. Copy linum.el to your
;; load-path and add to your .emacs:
;; (require 'linum)
;; Then toggle display of line numbers with M-x linum-mode. To enable
;; line numbering in all buffers, use M-x global-linum-mode.
;;; Code:
(defconst linum-version "0.9wza")
(defvar linum-overlays nil "Overlays used in this buffer.")
(defvar linum-available nil "Overlays available for reuse.")
(defvar linum-before-numbering-hook nil
"Functions run in each buffer before line numbering starts.")
(mapc #'make-variable-buffer-local '(linum-overlays linum-available))
(defgroup linum nil
"Show line numbers to the left of buffers"
:group 'convenience)
;;;###autoload
(defcustom linum-format 'dynamic
"Format used to display line numbers. Either a format string
like \"%7d\", 'dynamic to adapt the width as needed, or a
function that is called with a line number as its argument and
should evaluate to a string to be shown on that line. See also
`linum-before-numbering-hook'."
:group 'linum
:type 'sexp)
(defface linum
'((t :inherit (shadow default)))
"Face for displaying line numbers in the display margin."
:group 'linum)
(defcustom linum-eager t
"Whether line numbers should be updated after each command.
The conservative setting `nil' might miss some buffer changes,
and you have to scroll or press C-l to update the numbers."
:group 'linum
:type 'boolean)
(defcustom linum-delay nil
"Delay updates to give Emacs a chance for other changes."
:group 'linum
:type 'boolean)
;;;###autoload
(define-minor-mode linum-mode
"Toggle display of line numbers in the left marginal area."
:lighter "" ; for desktop.el
(if linum-mode
(progn
(if linum-eager
(add-hook 'post-command-hook (if linum-delay
'linum-schedule
'linum-update-current) nil t)
(add-hook 'after-change-functions 'linum-after-change nil t))
(add-hook 'window-scroll-functions 'linum-after-scroll nil t)
;; mistake in Emacs: window-size-change-functions cannot be local
(add-hook 'window-size-change-functions 'linum-after-size)
(add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
(add-hook 'window-configuration-change-hook
'linum-after-config nil t)
(linum-update-current))
(remove-hook 'post-command-hook 'linum-update-current t)
(remove-hook 'post-command-hook 'linum-schedule t)
(remove-hook 'window-size-change-functions 'linum-after-size)
(remove-hook 'window-scroll-functions 'linum-after-scroll t)
(remove-hook 'after-change-functions 'linum-after-change t)
(remove-hook 'window-configuration-change-hook 'linum-after-config t)
(remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
(linum-delete-overlays)))
;;;###autoload
(define-globalized-minor-mode global-linum-mode linum-mode linum-on)
(defun linum-on ()
(unless (minibufferp)
(linum-mode 1)))
(defun linum-delete-overlays ()
"Delete all overlays displaying line numbers for this buffer."
(mapc #'delete-overlay linum-overlays)
(setq linum-overlays nil)
(dolist (w (get-buffer-window-list (current-buffer) nil t))
(set-window-margins w 0)))
(defun linum-update-current ()
"Update line numbers for the current buffer."
(linum-update (current-buffer)))
(defun linum-update (buffer)
"Update line numbers for all windows displaying BUFFER."
(with-current-buffer buffer
(when linum-mode
(setq linum-available linum-overlays)
(setq linum-overlays nil)
(save-excursion
(mapc #'linum-update-window
(get-buffer-window-list buffer nil 'visible)))
(mapc #'delete-overlay linum-available)
(setq linum-available nil))))
(defun linum-update-window (win)
"Update line numbers for the portion visible in window WIN."
(goto-char (window-start win))
(let ((line (line-number-at-pos))
(limit (window-end win t))
(fmt (cond ((stringp linum-format) linum-format)
((eq linum-format 'dynamic)
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "d")))))
(width 0))
(run-hooks 'linum-before-numbering-hook)
;; Create an overlay (or reuse an existing one) for each
;; line visible in this window, if necessary.
(while (and (not (eobp)) (<= (point) limit))
(let* ((str (if fmt
(propertize (format fmt line) 'face 'linum)
(funcall linum-format line)))
(visited (catch 'visited
(dolist (o (overlays-in (point) (point)))
(when (string= (overlay-get o 'linum-str) str)
(unless (memq o linum-overlays)
(push o linum-overlays))
(setq linum-available (delete o linum-available))
(throw 'visited t))))))
(setq width (max width (length str)))
(unless visited
(let ((ov (if (null linum-available)
(make-overlay (point) (point))
(move-overlay (pop linum-available) (point) (point)))))
(push ov linum-overlays)
(overlay-put ov 'before-string
(propertize " " 'display `((margin left-margin) ,str)))
(overlay-put ov 'linum-str str))))
(forward-line)
(setq line (1+ line)))
(set-window-margins win width)))
(defun linum-after-change (beg end len)
;; update overlays on deletions, and after newlines are inserted
(when (or (= beg end)
(= end (point-max))
;; TODO: use string-match-p with CVS or new release
(string-match "\n" (buffer-substring-no-properties beg end)))
(linum-update-current)))
(defun linum-after-scroll (win start)
(linum-update (window-buffer win)))
(defun linum-after-size (frame)
(linum-after-config))
(defun linum-schedule ()
;; schedule an update; the delay gives Emacs a chance for display changes
(run-with-idle-timer 0 nil #'linum-update-current))
(defun linum-after-config ()
(walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible))
(provide 'linum)
;;; linum.el ends here
你可以拷贝下来直接命名为linum.el。
我把linum.el放在~/.emacs.d/package/目录下,~/.emacs配置如下:
;; 显示行号
(add-to-list 'load-path "~/.emacs.d/package")
(load "linum.el")
(require 'linum)
(global-linum-mode 1)
这样就可以显示行号了,哈哈,第一步成功,虽然我不知道add-to-list,load-path的意思,以后再学吧。
然后我发现用emacs录入.emacs文件的时候,我打不了中文,对,就是那个注释,我又蛋疼了,没有中文输入我用个屁阿,上网查吧。
我本来用的是scim,感觉还是满好用的。
scim安装越来越简单了,我原来空白机子上装的时候就两步:
apt-get install scim
然后就只要在/etc/X11/Xsession.d/目录下加一个文件,95xinput,写入如下内容就行了:
/usr/bin/scim -d
XMODIFIERS="@im=SCIM"
export XMODIFIERS
export GTK_IM_MODULE=scim
简单的一笔阿,但是后来我发现我错了。
emacs不能直接调用scim,找了半天都没有解决,继续找,终于找到一个scim-bridge,在wiki上找到的,所以用linux还得经常去这些网站阿,我直接把我看到的内容贴出来:
ScimBridge Chinese
scim-bridge.el 是 GNU Emacs 里面的 SCIM-Bridge 客户端. (EnglishVersion)
scim-bridge.el 可以保存不同缓存里面的输入状态, 这样你可以在 Emacs 里快速的输入中文, 而不用反复的切换全局的输入状态, 非常方便.
Contents
1. 什么是 SCIM?
2. 安装
3. 自定义
4. 截图
什么是 SCIM?
SCIM 是一个通用的智能输入法平台 (支持 中文, 日文, 韩文和许多欧洲语言), 可以使用在 POSIX 风格的操作系统, 包括 Linux 和 BSD.
安装
* 安装 SCIM:
o 在 Debian 里, 步骤非常简单:
sudo aptitude install scim scim-bridge-agent scim-bridge-client-gtk scim-bridge-client-qt4 scim-qtimm -y
o 你还可以使用下列命令来安装"拼音输入法”:
sudo aptitude install scim-pinyin -y
* 安装 scim-bridge.el:
o 从 scim-bridge.el project in Launchpad 里下载最新的压缩包.
o 让 Emacs 禁用 XIM:
+ 加入以下的命令到 ~/.Xresources:
Emacs*useXIM: false
+ 然后执行下列命令生效:
xrdb ~/.Xresources
o 加入 scim-bridge.el 到 load-path:
+ 解压 scim-bridge 的压缩包并放在 “~/elisp” 目录下, 然后添加下列命令到 ~/.emacs:
(add-to-list 'load-path (expand-file-name "~/elisp"))
o 修改 SCIM 的切换键:
+ 应为 Ctrl-Space 按键被Emacs默认绑定了, 所以要在 SCIM 图形设置界面里添加其他的按键, 比如 Super-Space (其他任意键也可以).
o 加载并设置 scim-bridge.el:
+ 加入下列到 ~/.emacs:
;; 加载.
(require 'scim-bridge-zh-si)
;;; 如果你使用繁体中文, 用 (require 'scim-bridge-zh-tr) 替换.
;; 加载 ~/.emacs 后自动开启 scim-mode.
(add-hook 'after-init-hook 'scim-mode-on)
;; 设置输入法切换键
(scim-define-common-key (kbd "s-SPC") t)
;; 使用 C-SPC 用作标记命令.
(scim-define-common-key (kbd "C-SPC") nil)
;; 使用 C-/ 用作撤销命令.
(scim-define-common-key (kbd "C-\\") nil)
;; 设置不同输入状态下光标颜色.
(setq scim-cursor-color '("red" "blue" "limegreen"))
现在按一下 Suepr-Space, 开始输入中文吧。
自定义
* 你可以通过下列方法自定义 scim-bridge.el:
M-x customize-group RET scim-bridge RET
我已经把相关的文档翻译成简体中文和繁体中文, enjoy!
我一步步照作,就是scim的切换键换成了shift-space,其他一模一样,然后打开emacs,就可以切换输入法了。之前用那些什么LC_CTYPE=zh_CN.UTF-8 emacs,可以弹出scim,结果只有英文的,我奶奶的,弹了比没弹出更让我蛋疼。
话说,我这时已经可以弹出scim那个框了,而且那个框中确实有智能拼音四个字,我郁闷的发现,我仍然只能输入中文,我的天呢,还让不让人活阿。
我继续找方法,发现网上没这种情况阿,我公司自己的机子好多网是不能上的,我们用的是远程客户端。无意间,我用本机的firefox查询的时候(我一般不用本机上网),发现我打不进中文,我知道了,不是emacs的问题,是我的scim出问题了,之前网上看到有人说用ibus可以在emacs中输入中文,我当时把scim删了,装了一个ibus,发现不好用,而且ibus-el在我们有限的网络上也找不到,就把ibus又删了,重装会scim,我差点背叛了它,可是最终还是回来了,这时候有个问题,我不知道要装scim-pinyin阿,第一次装的时候都是默认帮我把这个包装在上面的,可是这次他不帮我装了,发现了这个问题,我终于搞定了。
scim没问题了,emacs也好了,我的emacs征程要开始了。