我的emacs安裝

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 <[email protected]>
;; 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征程要開始了。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章