2013-07-09 27 views
2

有人請給我一隻手重映射org-shiftmetaright | org-shiftmetaleft[shift-select-meta]left-word | [shift-select-meta]right-word]。我們的目標是在組織模式下一舉突出選擇區域(右側或左側),而不是改變標題的級別。當我釋放輪班時不會突出顯示,但仍然可以將整個單詞向左或向右跳。重映射org-shiftmetaright | org-shiftmetaleft爲[shift-select-meta]左字| [shift-select-meta] right-word]

我會想象left-wordright-word可能有在交互式命令,或者類似的東西插入符號"^",因此對於左移位字或右移字沒有獨立的功能。

(defvar custom-keys-mode-map (make-keymap) "custom-keys-mode keymap.") 

(define-minor-mode custom-keys-mode 
    "A minor mode so that my key settings override annoying major modes." 
    t " my-keys" 'custom-keys-mode-map) 

(custom-keys-mode 1) 

(defun my-minibuffer-setup-hook() 
    (custom-keys-mode 0)) 

(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook) 

(defadvice load (after give-my-keybindings-priority) 
    "Try to ensure that my keybindings always have priority." 
    (if (not (eq (car (car minor-mode-map-alist)) 'custom-keys-mode)) 
     (let ((mykeys (assq 'custom-keys-mode minor-mode-map-alist))) 
     (assq-delete-all 'custom-keys-mode minor-mode-map-alist) 
     (add-to-list 'minor-mode-map-alist mykeys)))) 

(ad-activate 'load) 

;; (define-key custom-keys-mode-map (kbd "<C-key>") 'some-command) 

(define-key custom-keys-mode-map (kbd "M-<left>") 'left-word) 
(define-key custom-keys-mode-map (kbd "M-<right>") 'right-word) 

(define-key custom-keys-mode-map (kbd "M-S-<left>") 'left-word) 
(define-key custom-keys-mode-map (kbd "M-S-<right>") 'right-word) 

編輯:這裏是bindings.el我希望看到在使用組織模式的功能:

(defun right-word (&optional n) 
    "Move point N words to the right (to the left if N is negative). 

Depending on the bidirectional context, this may move either forward 
or backward in the buffer. This is in contrast with \\[forward-word] 
and \\[backward-word], which see. 

Value is normally t. 
If an edge of the buffer or a field boundary is reached, point is left there 
there and the function returns nil. Field boundaries are not noticed 
if `inhibit-field-text-motion' is non-nil." 
    (interactive "^p") 
    (if (eq (current-bidi-paragraph-direction) 'left-to-right) 
     (forward-word n) 
    (backward-word n))) 

(defun left-word (&optional n) 
    "Move point N words to the left (to the right if N is negative). 

Depending on the bidirectional context, this may move either backward 
or forward in the buffer. This is in contrast with \\[backward-word] 
and \\[forward-word], which see. 

Value is normally t. 
If an edge of the buffer or a field boundary is reached, point is left there 
there and the function returns nil. Field boundaries are not noticed 
if `inhibit-field-text-motion' is non-nil." 
    (interactive "^p") 
    (if (eq (current-bidi-paragraph-direction) 'left-to-right) 
     (backward-word n) 
    (forward-word n))) 
+0

'org-shiftmetaleft'是一個函數。 '[shift-select-meta] left-word'是...? – phils

+0

這就是我說的方式:shift + alt + left和shift + alt + right這些是在OSX上向左或向右突出顯示/選擇一個單詞的方式,我也認爲Windows也是如此(但自從我'已經使用該操作系統)。從本質上講,我只需要禁用這些鍵的組織模式映射,而我以前的禁用嘗試都不起作用,所以我想重新映射。 – lawlist

+0

更好地使用'C-h k'或'C-h c'來詢問Emacs如何表示鍵。在這種情況下''。 – phils

回答

5

當你只是想退回到默認行爲對於這些綁定,我們可以簡單地刪除組織模式覆蓋。

(eval-after-load "org" 
    '(progn 
    (define-key org-mode-map (kbd "<M-S-left>") nil) 
    (define-key org-mode-map (kbd "<M-S-right>") nil) 
    (define-key org-mode-map (kbd "<M-left>") nil) 
    (define-key org-mode-map (kbd "<M-right>") nil))) 
+0

再次感謝您的幫助。如果沒有這個線程,通過重新映射一堆密鑰而不理解備選方法來取消設置特定於模式的綁定,我會混淆我的init.el文件。 – lawlist

2

信不信我想做的事,這也。我跟着上面 - 我也重新綁定了這些命令到C-鍵:

(eval-after-load "org" 
'(progn 
(define-key org-mode-map (kbd "<M-S-left>") nil) 
(define-key org-mode-map (kbd "<M-S-right>") nil) 
(define-key org-mode-map (kbd "<M-left>") nil) 
(define-key org-mode-map (kbd "<M-right>") nil) 
(define-key org-mode-map [C-S-right] 'org-shiftmetaright) 
(define-key org-mode-map [C-S-left] 'org-shiftmetaleft) 
(define-key org-mode-map [C-right] 'org-metaright) 
(define-key org-mode-map [C-left] 'org-metaleft) 
(define-key org-mode-map [C-S-return] 'org-insert-todo-heading) 
)) 
3

如果你只是設置(setq org-replace-disputed-keys t),組織模式將重新映射這些相互矛盾的鑰匙。這也是可取的,因爲您仍然可以在日期選擇中使用Shift +箭頭鍵。

有關更多信息,請參閱http://orgmode.org/manual/Conflicts.html