版權聲明

所有的部落格文章都可以在右邊[blog文章原始檔案]下載最原始的文字檔案,並依你高興使用 docutil 工具轉換成任何對應的格式方便離線閱覽,除了集結成書販賣歡迎任意取用,引用
顯示具有 emacs 標籤的文章。 顯示所有文章
顯示具有 emacs 標籤的文章。 顯示所有文章

narrowing

Narrowing 可以暫時取得 buffer 中某個區域, 可以放心編輯它並確保其他未選區域不會受 到影響, 把特定區域從 buffer 中取出的動作 emacs 稱作 narrow , 這個選出的區域稱為 accessible portion, 取消 narrow 返回原 buffer 稱作 widening.

C-x n n
(narrow-to-region) 將 mark point 到目前游標位置的區域做 narrowing.
C-x n w
(widen) 返回原先buffer.
C-x n p
(narrow-to-page) 將current page narrowing.
C-x n d
(narrow-to-defun) Narrow down to the current defun.

Move region up or down

在http://blog.csdn.net/delphinew/archive/2008/02/29/2131689.aspx看到的, 滿不錯的整理一下自己備忘.

在Emacs中使用Alt+up Alt+down移動mark region

;; ----------------------------------------------------
;; Alt+up Alt+down 移動mark region
;; ----------------------------------------------------

(defun move-region-around (direction beg end)
 (let (real-beg
       real-end
       target-beg
       deactivate-mark
       text)
   (save-excursion
     (goto-char beg)
     (setq real-beg (line-beginning-position))

     (when (equal direction 'up)
       (setq target-beg (line-beginning-position 0)))

     (goto-char end)
     (setq real-end (line-beginning-position 2))

     (when (equal direction 'down)
       (setq target-beg (copy-marker (line-beginning-position 3)))) ;must use marker

     (setq text (buffer-substring-no-properties real-beg real-end))
     (delete-region real-beg real-end)
     (goto-char target-beg)
     (insert text)
     )

   (set-mark (+ target-beg (- real-end real-beg 1)))
   (goto-char target-beg)
   (setq transient-mark-mode 'only)))


(defun move-region-up (beg end)
 (interactive "r")
 (move-region-around 'up beg end))

(defun move-region-down (beg end)
 (interactive "r")
 (move-region-around 'down beg end))

(global-set-key (quote [M-up]) (quote move-region-up))
(global-set-key (quote [M-down]) (quote move-region-down))
(global-set-key "\C-c2" 'circle-windows)

Note

好會會造成transient-mark-mode disable ??

cedet-1.0pre4 安裝 (win32 sample)

將cedet-1.0pre4解壓縮.

打開MSYS (Mingw 的 shell 工具),進入cedet-1.0pre4的解壓縮目錄.

make (這邊用我自己的emacs path當例子)

$ make EMACS="C:\emacs-22.3\emacs-22.3\bin\emacs.exe"

.emacs setting

依照需求設定

;; Load CEDET
(load-file "~/cedet-VERSION/common/cedet.el")

;; Enabling various SEMANTIC minor modes.  See semantic/INSTALL for more ideas.
;; Select one of the following:

;; * This enables the database and idle reparse engines
;;(semantic-load-enable-minimum-features)

;; * This enables some tools useful for coding, such as summary mode
;;   imenu support, and the semantic navigator
(semantic-load-enable-code-helpers)

;; * This enables even more coding tools such as the nascent intellisense mode
;;   decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-guady-code-helpers)

;; * This turns on which-func support (Plus all other code helpers)
;; (semantic-load-enable-excessive-code-helpers)

;; This turns on modes that aid in grammar writing and semantic tool
;; development.  It does not enable any other features such as code
;; helpers above.
;; (semantic-load-enable-semantic-debugging-helpers)

Emacs pylint+flymake

pylint是python上面的lint, lint是古早用於C語言語法檢測的 工具, lint支援emacs..不僅如此lint支援emacs的flymake-mode.

flymake-mode是emacs上面相當強大的語法檢察工具, 他透過外部 程式進行檢查,然後依照檢查結果反應到編輯的buffer.

安裝

安裝pylint還挺煩的,照步驟慢慢來吧..

  1. Download pylint.

    http://www.logilab.org/857

  2. Download logilab-astng

    http://www.logilab.org/projects/astng

  3. Download logilab-common

    http://www.logilab.org/projects/common

  4. Download optik

    http://optik.sourceforge.net/

  5. 將每個tarbal解壓縮,並進入解壓縮目錄執行:

    python setup.py install
    

Note

如果不放心可以到各package的/test目錄下跑測試

  1. 建立一個python script 'epylint' (注意!!沒有副檔名py喔)
#!/usr/bin/env python

import re
import sys

from subprocess import *

p = Popen("pylint -f parseable -r n --disable-msg-cat=C,R %s" %
        sys.argv[1], shell = True, stdout = PIPE).stdout

for line in p.readlines():
  match = re.search("\\[([WE])(, (.+?))?\\]", line)
  if match:
      kind = match.group(1)
      func = match.group(3)

      if kind == "W":
         msg = "Warning"
      else:
         msg = "Error"

      if func:
          line = re.sub("\\[([WE])(, (.+?))?\\]",
                        "%s (%s):" % (msg, func), line)
      else:
          line = re.sub("\\[([WE])?\\]", "%s:" % msg, line)
  print line,

p.close()
  1. 將 'epylint' 丟進環境變數path的目錄中好讓flymake-mode可以收尋到.
  2. .emacs增加
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
                 'flymake-create-temp-inplace))
     (local-file (file-relative-name
                  temp-file
                  (file-name-directory buffer-file-name))))
(list "epylint" (list local-file))))

(add-to-list 'flymake-allowed-file-name-masks
         '("\\.py\\'" flymake-pylint-init)))

** 額外的keybind/和進入python mode 自動啟動參考

(add-hook 'python-mode-hook
     (lambda ()
          (flymake-mode)
          (local-set-key (kbd "\C-c e")
                      'flymake-display-err-menu-for-current-line)
          (local-set-key (kbd "\C-c `") 'flymake-goto-next-error)))

執行

進入python-mode 執行指令(假如你沒有設定自動啟動):

M-x flymake-mode

你會看到python script有藍色的代表警告,紅色代表錯誤.

想知道錯誤原因可以使用function:

M-x flymake-display-err-menu-for-current-line

Emacs scroll & Page up Page Down

一直都覺得使用Emacs的時候在scroll的時候怪怪的,總是和 Window上面的Editor不一樣,首先當游標移到畫面頂端或是尾部 的時候Emacs會直接幫你把遊標那一行做畫面置中的動作,這對 於ultraedit用習慣的人來說實在很不方便,常常一下子就不知道 發生甚麼事情,對於寫程式的影響更大,瀏覽程式的思考常常 因此被打斷,然後看程式的時候不時想到這問題十足惱人, 如果您也有相同問題請將下面lisp code加入.emacs中:

;; -------------------------------------
;; Scroll Setting
;; -------------------------------------
(setq scroll-margin 3
    scroll-conservatively 10000)

PageUp & PageDown

Emacs對於這兩顆按鍵榜定的功能是(scroll-up) 和 (scroll-down),其實 沒甚麼太大的問題,但是這又和window上面的編輯器不一樣了,當你 捲動到第一頁再繼續按Page Up鍵, Windows上面的編輯器一般的做法 會幫你把游標移到第一行,有的會幫你移動到第一個字, Emacs卻是 發出逼逼~ 然後甚麼都不做..

如果希望Emacs幫你移動游標到首行或是尾行代替逼逼叫,請加入下面 key bind:

;; ---------------------------------------------
;; Page down/up move the point, not the screen.
;; In practice, this means that they can move the
;; point to the beginning or end of the buffer.
;; ---------------------------------------------
(global-set-key [next]
 (lambda () (interactive)
   (condition-case nil (scroll-up)
     (end-of-buffer (goto-char (point-max))))))

(global-set-key [prior]
 (lambda () (interactive)
   (condition-case nil (scroll-down)
     (beginning-of-buffer (goto-char (point-min))))))

Python refactoring tool in Emacs

Download:

http://sourceforge.net/projects/bicyclerepair/

Install

  • 解壓縮

  • 到解壓縮目錄安裝bicyclerepair:

    python setup.py install
    

    Note

    安裝的時候我有遇到錯誤,不過後來到/bike下執行testall.py又都過關 所以不理發生的錯誤

  • 安裝 pymacs -- 直接去安網抓再照指示安裝,不要用bikerepair裡包含的:

    http://pymacs.progiciels-bpi.ca/
    
  • .emacs 增加

;; bikeemacs
(pymacs-load "bikeemacs" "brm-")
(brm-init)
  • 開一個python file可以看到menu會出現BicycleRepairman

Emacs Basic 1 (Move Copy Cut Paste)

Rst轉出來的table blogger怪怪的也懶的修,直接看google doc好了 http://docs.google.com/Doc?id=dgtnhgb3_66fjt4xmcw

Yasnippet

簡介

Yasnippet 是一個讓emacs變成和textmate一樣好玩的elisp

下載處 yaSnippet

作者很用心幫懶人準備好了yasnippet-bundle, 假如你覺得自己可能不久後 可能會自己寫snippet加入, 那還是建議下載正式版本研究一下.

安裝

  • bundle版本
(add-to-list 'load-path
    "~/.emacs.d/plugins")
  • 正常版本
(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
(yas/load-directory "/path/to/the/snippets/directory/")

emacs Ctrl-X Ctrl-V Ctrl-C

如何將emacs設定如下:

Ctrl-X  Cut
Ctrl-C  Copy
Ctrl-V  Paste
  • 啟動cua-mode:

    M-x cua-mode
    
  • 要讓emacs每次啟動都有一樣的效果

    • 在.emacs中加上
;;Ctrl-x ctrl-x ctrl-v  (windows style)
(cua-mode t)
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

Emacs rst-mode

安裝

  • rst.el 另存新檔rst.el到emacs的收尋路徑
  • 在.emacs中加入
(require 'rst)
(setq auto-mode-alist
(append '(("\\.txt$" . rst-mode)
      ("\\.rst$" . rst-mode)
      ("\\.rest$" . rst-mode)) auto-mode-alist))

Local variables

假如 (set enable-local-variables t) 將下面敘述放在第一行可以觸發rst mode

.. _*_ mode: rst -*-

或是下面放檔案最後

..
Local Variables:
mode: rst
End:

Section 快捷

在title下面輸入C-- or C-=:

Title1
^^

查看目前Section hierarchy:

M-x rst-display-decorations-hierarchy [C-c C-h]

Move to pre section:

M-x rst-backward-section [C-c C-p]

Move to next section:

M-x rst-forward-indented-block [C-c C-n]

Mark section:

M-x rst-mark-section [C-c C-m]

Config

Indent設定:

(setq rst-default-indent 4)

Block

先mark要作用的區域

智慧右移:

M-x rst-shift-region-right [C-c C-r]

智慧左移:

M-x rst-shift-region-left [C-c C-l]

自動bullet list:

M-x rst-enumerate-region [C-c C-e]

Line Block:

Apples
Oranges
Bananas

M-x rst-toggle-line-block [C-c C-d]::

| Apples
| Oranges
| Bananas

Compile

M-x rst-compile [C-c 1]

Emacs color-theme 1. 下載 http://www.emacswiki.org/cgi-bin/wiki?ColorTheme 2. 在.emacs 下 (~/.emacs) **(win32用 echo %HOME% 確認 home 目錄,如果沒有可以設定一個) **(設定方式 我的電腦->滑鼠右鍵->內容->進階->環境變數) a. 將路徑載入 (setq load-path(cons "/安裝路徑" load-path)) 3. 從新啟動emacs (假如你的安裝路徑是在emacs本來就可以收尋的範圍則不用啟動) a. M-x color-theme-select b. 選一個喜歡的theme 按'd'
像上圖一樣 (color-theme-billw)就是更換theme的function name c. .emacs加入 (require 'color-theme) (color-theme-initialize) (color-theme-billw) <------ 這行換成你喜歡的theme
Related Posts with Thumbnails