GNU/Emacs

這本是我個人主頁上用Emacs-wiki寫的一篇關於Emacs的筆記,因爲個人主頁站點不能用了,現在轉移到這裏。不過 ,雖然我會做一些改變,但是還是沒有Emacs-wiki發佈的那麼好!

什麼是Emacs ? Emacs is the extensible, customizable, self-documenting real-time display editor. 簡單的說, EMACS是一個以編輯器爲主體的系統.它支持解析語言LISP,這就奠定了它的無限擴展的特性.你可以將任何希望做的事情以LISP寫的插件方式,來擴展EMACS ,使其支持這一功能.由於它這種 與時代俱進 的設計思想和結構體系,讓它在漫長的30 年中一直廣爲流行.它的作者Richard Stallman 還獲得麥克阿瑟基金會24萬美金的 天才獎 .

我總認爲 一個好的軟件不是以它的外在形式,而是以它的內在邏輯緊密的聯繫在一起. 當你不曾領會它的內在邏輯時,它那看似雜亂無章苦澀難懂的外表足以讓你望而卻步.但是,當你真正領會到它的精髓之際,你會幡然醒悟,突然發現什麼纔是真正的 方便, 智能自動化 ! 這是一個天才的天才發明.

GNU/Emacs能幹什麼?

在知道GNU/Emacs能做什麼之前,先看看我用Emacs都做了些什麼吧!我想沒有人敢很明確的告訴你GNU/Emacs究竟能做什麼,不能做什麼.沒有界限就是它的界限!

  • 看看這張圖片,這是我用Emacs收發電子郵件.看到沒有, 非常的方便.自動給你列出信件頭(包括附件),選中你要查看的郵件,Emacs會自動給你另外分隔一個顯示郵件主體的區域,並且標記了對方的發信端類型和附件類型.默認是以文本格式把附件顯示在郵件主體後面,如果你看到的是一堆整齊的亂碼,那麼請按'.',你可以很輕易的保存,執行附件.當然,如果是發郵件,添加附件也是非常簡單的.你可以把添加的命令綁定成你喜歡的快捷鍵.更詳細的使用方法看Emacs Mew.
  • 再看看這張圖片這是我用Emacs瀏覽網站. 你幾乎不需要離開Emacs就能得到你想要的.當然,你或許會用其它的圖形瀏覽器, 但是,如果你是用瀏覽器去找有用的資訊東西而不是去看一些華俏的東西打發時間的話,這玩意還是很不錯的,快捷,簡單!更多關於用Emacs瀏覽網頁的請看這裏 Emacs_W3m .
  • 這張圖是Emacs做其本來職業的圖片,你看它做的多好! 自動的分析函數,列出項目結構,記錄最近編輯過的文檔,自動在各函數間跳轉......
  • 其實你無需去遠方,一切都在你身旁......的確如此! If you want to Edit, Compile and Debug the files in the remote hoste, What did you do ? tall me please !其實,你無需登錄到遠方的服務器,在那個並不靈活的Terminal 中很機械的弄那些代碼.你只需要稍微設置一下Emacs就足夠了,一切就像在本地一樣:一樣的操作靈活,一樣的反應快速,一樣的賞心悅目......
  • 知道我這個文檔是如何寫成的嗎?不是一條一條HTML語句湊成的.也不是用What see What get tools 一點一點修理出來的.我寫這個網站上的任何文檔的時候, 只需要關心我的內容就可以了,像寫文章一樣,其它的事情Emacs-wiki做好了,它自動生成了如此精美的網頁.羨慕吧!看看這張圖 .

如何使用GNU/Emacs ?

知道了GNU/Emacs能幹個啥了,就讓我們開始乾點啥子吧.如果你的系統上還沒有安裝Emacs的話(這幾乎不可能,如果我沒有記錯的話,Emacs是Linux系統默認安裝的.)如果你用的是該死的Windows系統的話,請到這裏看看Windows上的Emacs如何設置和使用.或者下載這個手冊自己Have a look 一下!

基本操作

我是憑自己的使用習慣來寫這個文檔的.可能很多地方不太 標準 .不過,也無大礙,本來寫給自己看的,我就是這麼開始我的Emacs之旅的.呵呵!首先聲明一下:C 是Ctrl健;M是Atl健(終端和MAC機上是Esc健.(聲明完畢)  

按健 作用
C-x u 取消上一步操作
C-x C-f 查找文件
C-x C-w 文件另存
C-x C-s 保存文件
C-x C-c 退出Emacs
C-x C-h 查看在線幫助

以上是最基本的操作,如果需要在Emacs中編輯文檔,那麼需要知道一下操作:

按健 作用 按鍵 作用
C-v 下滾一頁 M-v 上滾一頁
C-l 本行居中 C-k 刪除本行
C-f 前移一字 C-b 後移一字
M-f 前移一詞 M-b 後移一詞
C-n 下移一行 C-p 上移一行
C-a 跳到行首 C-e 跳到行尾
M-a 跳到句首 M-e 跳到句尾
M-< 光標到頂 M-> 光標到底
M-w 複製所選區域 C-w 剪切所選區域
C-s 文中向後查找 C-y 粘貼緩衝區
C-@ 設置Mark M-g 跳至指定行

其中,複製,剪切之前要用C-@設定Mark,然後用C-n,C-p或方向鍵選中要複製或剪切的區域,然後用C-w或M-w進行復制或剪切操作.至此,就完全可以用Emacs編輯文檔了.

Emacs的配置

 ;; Red Hat Linux default .emacs initialization file  ; -*- mode: emacs-lisp -*-

;; Set up the keyboard so the delete key on both the regular keyboard
;; and the keypad delete the character under the cursor and to the right
;; under X, instead of the default, backspace behavior.
(global-set-key [delete] 'delete-char)
(global-set-key [kp-delete] 'delete-char)

;; turn on font-lock mode
(global-font-lock-mode t)
;; enable visual feedback on selections
(setq-default transient-mark-mode t)

;; always end a file with a newline
(setq require-final-newline t)

;; stop at the end of the file, not just add lines
(setq next-line-add-newlines nil)

(when window-system
  ;; enable wheelmouse support by default
  (mwheel-install)
  ;; use extended compound-text coding for X clipboard
  (set-selection-coding-system 'compound-text-with-extensions))

(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(case-fold-search t)
 '(current-language-environment "Chinese-GB")
 '(default-input-method "chinese-py-punct")
 '(ecb-options-version "2.32")
 '(global-font-lock-mode t nil (font-lock))
 '(show-paren-mode t nil (paren))
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t)
 '(uniquify-buffer-name-style (quote forward) nil (uniquify)))
(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 )

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;這下面的是我自己設置的工作環境!           蕭皓天
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq inhibit-startup-message t)
  (set-selection-coding-system 'cn-gb-2312)
  (setq inhibit-default-init t)
  (set-scroll-bar-mode nil)
  (setq default-tab-width 4)
  (auto-image-file-mode)
  (tool-bar-mode nil)
  (menu-bar-mode nil)
 
  (setq column-number-mode t)
  (setq kill-ring-max 200)
  (setq default-major-mode 'text-mode)
  (define-key c-mode-map [return] 'newline-and-indent)
  (c-toggle-auto-state)
  (c-toggle-hungry-state)

  (add-hook 'c-mode-hook
     '(lambda ()
 (c-set-style "k&r"))
  ;;set c++ style as stroustrup style
  (add-hook 'c++-mode-hook
     '(lambda()
 (c-set-style "stroustrup"))

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;顯示時間和郵件提示.
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (display-time-mode 1)
  (setq display-time-24hr-format t)
  (setq display-time-day-and-date t)
  (setq display-time-use-mail-icon t)
  (setq display-time-interval 10)
 
  (add-hook 'c-mode-hook '(lambda () (c-set-style "k&r")))
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;一些高級設置,方便工作.                                          ;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (require 'wb-line-number) ;;顯示行號,看代碼的時候用最好.
  ;;(wb-line-number-toggle)
 
  (require 'ibuffer)
  (global-set-key (kbd "C-x C-b") 'ibuffer)

  (add-to-list 'load-path "/usr/share/emacs/21.2/eieio")
  (add-to-list 'load-path "/usr/share/emacs/21.2/semantic")
  (setq semantic-load-turn-everything-on t)
  (require 'semantic-load)
  (add-to-list 'load-path "/usr/share/emacs/21.2/speedbar")

  (add-to-list 'load-path "/usr/share/emacs/21.2/ecb")
  (require 'ecb)
  (setq ecb-auto-activate t
  ecb-tip-of-the-day nil
  inhibit-startup-message t
  ecb-auto-compatibility-check nil
  ecb-version-check nil)

  ;(require 'tabbar)
  ;(tabbar-mode)
  ;(global-set-key (kbd "") 'tabbar-backward-group)
  ;(global-set-key (kbd "") 'tabbar-forward-group)
  ;(global-set-key (kbd "") 'tabbar-backward)
  ;(global-set-key (kbd "") 'tabbar-forward)

  (require 'color-theme)
  ;;(color-theme-blue-mood)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;          綁定一些自己的快捷鍵 .
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (global-set-key (kbd "M-z") 'color-theme-blue-sea)
  (global-set-key (kbd "M-g")  'goto-line)
  (global-set-key (kbd "M-2") 'wb-line-number-enable)
  (global-set-key (kbd "C-2") 'set-mark-command)
 
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;                  以下是其它插件的功能擴展                      ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;                     在Emacs中收發郵件.                         ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mew")
  (autoload 'mew "mew" nil t)
  (autoload 'mew-send "mew" nil t)
  (setq mew-icon-directory "/usr/local/share/emacs/site-lisp/mew/etc")
  (setq mew-use-cached-passwd t)
  (setq mew-pop-size 0) ;; 沒有限止郵件大小
  (setq mew-pop-delete nil)
  (setq mew-config-alist
     '(("default"
       ("name"         .  "Dragon")
       ("user"         .  "xiao_crazy")
       ("mail-domain"  .  "163.com")
       ("pop-server"   .  "pop3.163.com")
       ("pop-port"     .  "110")
       ("pop-user"     .  "xiao_crazy")
       ("pop-auth"     .  pass)
       ("smtp-server"  .  "smtp.163.com")
       ("smtp-port"    .  "25")
       ("smtp-user"    .  "xiao_crazy")
       ("smtp-auth-list"  .  ("LOGIN"  "PLAIN"  "CRAM-MD5")))))
  (when (boundp 'utf-translate-cjk)
        (setq utf-translate-cjk t)
        (custom-set-variables
           '(utf-translate-cjk t)))
  (if (fboundp 'utf-translate-cjk-mode)
      (utf-translate-cjk-mode 1))
  (require 'flyspell)
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;                      End of MEW in Emacs                         ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;                  在EMACS中瀏覽WEB網頁並支持中文                  ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
  (require 'w3m-load)
  (setq w3m-display-inline-image t)
  (setq w3m-use-mule-ucs t)
  (setq w3m-use-toolbar t)
  (setq w3m-use-cookies t)
  (setq w3m-bookmark-file-coding-system 'chinese-iso-8bit)
  (setq w3m-coding-system 'chinese-iso-8bit)
  (setq w3m-default-coding-system 'chinese-iso-8bit)
  (setq w3m-file-coding-system 'chinese-iso-8bit)
  (setq w3m-file-name-coding-system 'chinese-iso-8bit)
  (setq w3m-terminal-coding-system 'chinese-iso-8bit)
  (setq w3m-input-coding-system 'chinese-iso-8bit)
  (setq w3m-output-coding-system 'chinese-iso-8bit)
  (setq w3m-tab-width 8)
  (setq w3m-home-page "http://www.gun.org")
  (setq w3m-view-this-url-new-session-in-background t)

  (add-hook 'w3m-fontify-after-hook 'remove-w3m-output-garbages)
  (defun remove-w3m-output-garbages()
    (interactive)
    (let ((buffer-read-only))
   (setf (point) (point-min))
   (while (re-search-forward "[/200-/240]" nil t)
     (replace-match " "))
   (set-buffer-multibyte t))
    (set-buffer-modified-p nil))

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;                  End of configure W3M in Emacs                    ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;        用EMACS 打開,編輯遠程的文件,設定TELNET,FTP在EMACS中.       ;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (add-to-list 'load-path "/usr/share/emacs/21.2/tramp/lisp")
  (setq tramp-unified-filenames t)
  (setq tramp-default-method "scp")
  (setq tramp-auto-save-directory "/tmp")
  (setq auto-save-file-name-transtorms
    '(("//~/[~/]*://(.+///)" "/tmp///2")))
  (setq tramp-chunksize 448)
  (setq ange-ftp-default-user t)
  (require 'ange-ftp)
  (require 'tramp)

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(require 'emacs-wiki)

(add-hook 'emacs-wiki-mode-hook
   (lambda ()
     (define-key emacs-wiki-mode-map (kbd "C-c C-h") 'emacs-wiki-preview-html)
     (define-key emacs-wiki-mode-map (kbd "C-c C-c") 'emacs-wiki-preview-source)
     (define-key emacs-wiki-mode-map (kbd "C-c C-v") 'emacs-wiki-change-project)

  ))

;; (setq emacs-wiki-grep-command "glimpse -nyi /"%W/"")

(setq emacs-wiki-publishing-directory "publish")

(setq emacs-wiki-meta-content-coding "gbk")
(setq emacs-wiki-directories '("~/WiKi"))
(setq emacs-wiki-meta-charset "gbk")
(setq emacs-wiki-style-sheet "<link rel='stylesheet' type='text/css' href='../css/main.css'>")

(setq emacs-wiki-inline-relative-to 'emacs-wiki-publishing-directory)

(defun emacs-wiki-preview-source ()
  (interactive)
  (emacs-wiki-publish-this-page)
  (find-file (emacs-wiki-published-file)))

(defun emacs-wiki-preview-html ()
  (interactive)
  (emacs-wiki-publish-this-page)
  (browse-url (emacs-wiki-published-file)))

(setq emacs-wiki-projects
      `(("default" . ((emacs-wiki-directories . ("~/WiKi"))))
        ("work" . ((fill-column . 65)
                 (emacs-wiki-directories . ("~/workwiki/"))))))

(require 'emacs-wiki-menu)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-emacs-wiki-chmod-644-published-file (file)
  (let* ((page (emacs-wiki-page-name file))
         (published (emacs-wiki-published-file page)))
         (shell-command (concat "chmod 644 " published))))

(add-hook 'emacs-wiki-after-file-publish-hook
          'my-emacs-wiki-chmod-644-published-file)

GNU/Emacs資源列表

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