2010-11-12 30 views
2

我試圖設置一些快捷鍵來使用Shift鍵來突出顯示文本。我可以使用pc-selection-mode,但不提供我想要的所有鍵綁定。例如,我希望能夠通過按Shift-Ctrl-down來移動標記整個段落,這在大多數MS文本編輯器中可以實現,但pc-selection-mode不允許您這樣做。GNU emacs:設置快捷鍵以突出顯示帶有Shift鍵的文本

我發現這個website其中有一個shift_mark.el文件我可以用來設置我想要的所有鍵綁定。我已將我的.xemacs/init.el文件加載到shift_mark.el

這是錯誤:

Warning (initialization): An error occurred while loading `/home/theory/phrkaj/\ 
.xemacs/init.el': 

Wrong type argument: arrayp, (shift right) 

所以我已經運行的Emacs與--debug-init,試圖找到問題。這是調試器想出了:

Debugger entered--Lisp error: (wrong-type-argument arrayp (shift right)) 
    signal(wrong-type-argument (arrayp (shift right))) 
    global-set-key((shift right) shift-mark-forward-char) 
    eval-buffer(#<buffer *load*<3>> nil "/home/theory/phrkaj/shift_mark.el" nil t) ; Reading at buffer position 1476 
    load-with-code-conversion("/home/theory/phrkaj/shift_mark.el" "/home/theory/phrkaj/shift_mark.el" nil nil) 
    load("~/shift_mark.el") 
    eval-buffer(#<buffer *load*<2>> nil "/home/theory/phrkaj/.xemacs/init.el" nil t) ; Reading at buffer position 25 
    load-with-code-conversion("/home/theory/phrkaj/.xemacs/init.el" "/home/theory/phrkaj/.xemacs/init.el" nil nil) 
    load("/home/theory/phrkaj/.xemacs/init.el" nil nil t) 
    load-file("/home/theory/phrkaj/.xemacs/init.el") 
    eval-buffer(#<buffer *load*> nil "/home/theory/phrkaj/.emacs" nil t) ; Reading at buffer position 253 
    load-with-code-conversion("/home/theory/phrkaj/.emacs" "/home/theory/phrkaj/.emacs" t t) 
    load("~/.emacs" t t) 
    #[nil "^H\205\264^@ \306=\203^Q^@\307^H\310Q\2027^@ \311=\2033^@\312\307\313\314#\203#^@\315\2027^@\312\307\313\316#\203/^@\317\2027^@\315\2027^@\307^H\320Q^Z\321^S\322\n\321\211#\210^K\321=\203_^@\323\324\325\307^H\326Q!\"^\\322\f\$ 
    command-line() 
    normal-top-level() 

這裏的shift_mark.el文件,該文件定義了一個字符前進的高亮部分:

(defun shift-mark-forward-char() 
    (interactive) 
    (shift-mark 'forward-char)) 

(global-set-key '(shift right) 'shift-mark-forward-char) 

任何幫助表示讚賞。

+0

什麼您使用的是Emacs版本嗎?你的帖子在GNU Emacs和XEmacs之間看起來不一致。另外,在XEmacs 21中,我沒有設置任何設置,在GNU Emacs 23中使用'pc-selection-mode','Ctrl + Shift + Down'按照你的要求工作。如果您啓動'emacs -q'或'xemacs -q'(即不加載配置文件),它是否適用? – Gilles 2010-11-12 15:24:47

回答

3

在GNU Emacs的,關鍵的結合應該像

(global-set-key [(shift right)] 'shift-mark-forward-char) 

[…]構造一個字面數組)。但我懷疑你是以這種錯誤的方式去做的。你在運行GNU Emacs,XEmacs還是兩者?什麼版本?除非你運行的是非常舊的版本,否則pc-selection-mode應該在GNU Emacs下做你想要的,並且在XEmacs下不需要安裝。如果您同時運行GNU Emacs和XEmacs的,你可以在你的.emacs使用下面的代碼:

(defvar running-xemacs (string-match "XEmacs" emacs-version)) 
(if (not running-xemacs) 
    (pc-selection-mode 1)) 
1

vshift-select-modeRET

shift-select-mode is a variable defined in `simple.el'. Its value is nil

Documentation: When non-nil, shifted motion keys activate the mark momentarily.

While the mark is activated in this way, any shift-translated point motion key extends the region, and if Transient Mark mode was off, it is temporarily turned on. Furthermore, the mark will be deactivated by any subsequent point motion key that was not shift-translated, or by any action that normally deactivates the mark in Transient Mark mode.

See `this-command-keys-shift-translated' for the meaning of shift-translation.

You can customize this variable.

這個變量在GNU Emacs的介紹23.1:

** Temporarily active regions

* The new variable shift-select-mode, non-nil by default, controls shift-selection. When Shift Select mode is on, shift-translated motion keys (e.g. S-left and S-down) activate and extend a temporary region, similar to mouse-selection.

* Temporarily active regions, created using shift-selection or mouse-selection, are not necessarily deactivated in the next command. They are only deactivated after point motion commands that are not shift-translated, or after commands that would ordinarily deactivate the mark in Transient Mark mode (e.g., any command that modifies the buffer).