GNU emacs: setting keybindings to highlight text with shift key
I'm trying to set some keybindings to use the Shift key to highlight text. I could use pc-selection-mode
, but that doesn't offer all the key bindings I want. For example, I'd like to be able to shift-mark an entire paragraph by pressing Shift-Ctrl-down which I can do in most MS text editors, but pc-selection-mode
doesn't allow you to do this.
I found this website which has a shift_mark.el
file I can use to set all the key bindings I want. I've put in my .xemacs/init.el
file to load shift_mark.el
.
This is 开发者_如何学Cthe error:
Warning (initialization): An error occurred while loading `/home/theory/phrkaj/\
.xemacs/init.el':
Wrong type argument: arrayp, (shift right)
So I've run Emacs with --debug-init
to try and find the problem. This is what the debugger came up with:
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()
Here's part of the shift_mark.el
file which defines the highlighting of one char forward:
(defun shift-mark-forward-char ()
(interactive)
(shift-mark 'forward-char))
(global-set-key '(shift right) 'shift-mark-forward-char)
Any help is appreciated.
Under GNU Emacs, the key binding should look like
(global-set-key [(shift right)] 'shift-mark-forward-char)
([…]
constructs a literal array). But I suspect you're going at this the wrong way. Are you running GNU Emacs, XEmacs, or both? What versions? Unless you're running extremely old versions, pc-selection-mode
should do what you want under GNU Emacs, and no setup should be required under XEmacs. If you run both GNU Emacs and XEmacs, you can use the following code in your .emacs
:
(defvar running-xemacs (string-match "XEmacs" emacs-version))
(if (not running-xemacs)
(pc-selection-mode 1))
C-hv shift-select-mode
RET
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.
This variable was introduced in 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).
精彩评论