2009-11-20 11 views
19

जैसा कि शीर्षक कहता है, कैसे एक emacs आगे-शब्द फ़ंक्शन के व्यवहार को बदलता है? उदाहरण के लिए, मान लीजिए [] कर्सर है। तब:बदलना Emacs फॉरवर्ड-वर्ड व्यवहार

my $abs_target_path[]= abs_path($target); 
<M-f> 
my $abs_target_path = abs[_]path($target); 

मैं जानता हूँ कि मैं सिर्फ एम एफ एम बी लेकिन जहां तक ​​मेरा सवाल है, कि आवश्यक नहीं होना चाहिए इस्तेमाल कर सकते हैं और मैं इसे बदलना चाहते हैं।

  1. जब मैं प्रेस एम एफ, मैं रिक्त स्थान या कहीं और के एक समूह के भीतर है कि क्या बात एक शब्द के भीतर है की परवाह किए बिना अगले शब्द के पहले अक्षर पर जाने के लिए, चाहते हैं: विशेष रूप से, मैं दो बातें करना चाहता हूँ।
  2. मोड-दर-मोड आधार पर शब्द-वर्णों को कस्टमाइज़ करें। आखिरकार, सीपीरल मोड में घूमना, टीएक्स मोड से अलग है।

तो, उपरोक्त उदाहरण में, आइटम 1 में एम-एफ मारने के बाद कर्सर 'ए' (और इसके बाईं ओर बिंदु) पर ले जाएगा। आइटम 2 मुझे अंडरस्कोर और सिगिल को शब्द वर्णों के रूप में परिभाषित करने की अनुमति देगा।

+0

, http: // stackoverflow .com/प्रश्न/1545851/कैसे-टू-मेक-फॉरवर्ड-वर्ड-पिछड़ा-शब्द-उपचार-अंडरस्कोर-ए-पार्ट-ऑफ-ए-वर्ड/1545 9 34 – Bahbar

उत्तर

30

प्रयास करें:

(require 'misc) 

फिर M-x forward-to-word का उपयोग करें और अगर यह तुम क्या चाहते करता है देखते हैं। इसके बाद आप M-f rebind कर सकते हैं, आदि

_ नहीं एक शब्द विभाजक बनाने के सी & सी ++ मोड के लिए (यानी यह एक शब्द घटक बनाने), तो आप इस करना होगा:

(modify-syntax-entry ?_ "w" c-mode-syntax-table) 
(modify-syntax-entry ?_ "w" c++-mode-syntax-table) 

अधिक जानकारी के लिए पर वाक्यविन्यास सारणी, this wiki page पढ़ें। सिंटेक्स टेबल आमतौर पर tex-mode-syntax-table और cperl-mode-syntax-table जैसे नामित होते हैं।

+0

क्या (x) Emacs का एक विशिष्ट संस्करण है जिसमें ' ('Misc) की आवश्यकता है' '_' वर्ण को वाक्यविन्यास तालिका में सफेद जगह पर ले जाया जाएगा? मुझे यह काम करने के लिए '(संशोधित-वाक्यविन्यास-प्रविष्टि? _ "-")' करना था। – sameers

+0

अब मैं ओएसएक्स पर जीएनयू एमएक्स 24.5 का उपयोग कर रहा हूं, और मुझे नहीं पता कि मैंने पहले यह कोशिश की थी, लेकिन मेरे '.emacs' में 'संशोधित-वाक्यविन्यास-प्रविष्टि' कॉल तालिका प्रविष्टि सेट नहीं करता है। जब मैं मिनी-बफर में टाइप करता हूं तो यह काम करता है। कोई विचार यह कैसे सभी मोड में काम करने के लिए? '(संशोधित-वाक्यविन्यास-प्रविष्टि? _" डब्ल्यू "मानक-वाक्यविन्यास-तालिका) 'कहता है कि' मानक-वाक्यविन्यास-तालिका 'एक शून्य-परिभाषा प्रतीक है। – sameers

+0

इससे 24.5.1' में गंभीर अंतराल के मुद्दे हो सकते हैं। – Zelphir

2

आगे-उसी-सिंटैक्स फ़ंक्शन भी देखें। शायद यह आपको आधार पर करने की जरूरत है।

+0

बहुत बहुत धन्यवाद! मुझे इस बारे में पता नहीं था और यह बहुत अच्छा काम करता है! मैंने यह पाया कि जो सभी एक साथ बंडल करते हैं - आगे बढ़ें/आगे बढ़ें: https://github.com/nixme/.emacs.d/blob/master/core/init-keybindings.el – fikovnik

1

मेरे पास एक मामूली मोड है जो वाक्य-आधारित आदेशों को वाक्यविन्यास परिवर्तन (और CamelCaseSubwords) पर संचालित करने के लिए बदलता है। यह कुछ स्वाद के लिए थोड़ा सा जुड़ा हुआ हो सकता है, लेकिन मुझे लगता है कि मैं मूल रूप से कभी भी एक चरित्र आंदोलन का उपयोग करता हूं।

https://bitbucket.org/jpkotta/syntax-subword

0

मैं अपने पिछले संपादक इस प्रकार कुछ और नियंत्रण की जरूरत के व्यवहार की नकल करना चाहता था, इसलिए यहाँ उस पर मेरी ले रहा है: अंडरस्कोर भाग के लिए

(defun my-syntax-class (char) 
    "Return ?s, ?w or ?p depending or whether CHAR is a white-space, word or punctuation character." 
    (pcase (char-syntax char) 
     (`?\s ?s) 
     (`?w ?w) 
     (`?_ ?w) 
     (_ ?p))) 

(defun my-forward-word (&optional arg) 
    "Move point forward a word (simulate behavior of Far Manager's editor). 
With prefix argument ARG, do it ARG times if positive, or move backwards ARG times if negative." 
    (interactive "^p") 
    (or arg (setq arg 1)) 
    (let* ((backward (< arg 0)) 
     (count (abs arg)) 
     (char-next 
      (if backward 'char-before 'char-after)) 
     (skip-syntax 
      (if backward 'skip-syntax-backward 'skip-syntax-forward)) 
     (skip-char 
      (if backward 'backward-char 'forward-char)) 
     prev-char next-char) 
    (while (> count 0) 
     (setq next-char (funcall char-next)) 
     (loop 
     (if (or       ; skip one char at a time for whitespace, 
      (eql next-char ?\n)   ; in order to stop on newlines 
      (eql (char-syntax next-char) ?\s)) 
      (funcall skip-char) 
     (funcall skip-syntax (char-to-string (char-syntax next-char)))) 
     (setq prev-char next-char) 
     (setq next-char (funcall char-next)) 
     ;; (message (format "Prev: %c %c %c Next: %c %c %c" 
     ;;     prev-char (char-syntax prev-char) (my-syntax-class prev-char) 
     ;;     next-char (char-syntax next-char) (my-syntax-class next-char))) 
     (when 
      (or 
      (eql prev-char ?\n)   ; stop on newlines 
      (eql next-char ?\n) 
      (and      ; stop on word -> punctuation 
      (eql (my-syntax-class prev-char) ?w) 
      (eql (my-syntax-class next-char) ?p)) 
      (and      ; stop on word -> whitespace 
      this-command-keys-shift-translated ; when selecting 
      (eql (my-syntax-class prev-char) ?w) 
      (eql (my-syntax-class next-char) ?s)) 
      (and      ; stop on whitespace -> non-whitespace 
      (not backward)    ; when going forward 
      (not this-command-keys-shift-translated) ; and not selecting 
      (eql (my-syntax-class prev-char) ?s) 
      (not (eql (my-syntax-class next-char) ?s))) 
      (and      ; stop on non-whitespace -> whitespace 
      backward     ; when going backward 
      (not this-command-keys-shift-translated) ; and not selecting 
      (not (eql (my-syntax-class prev-char) ?s)) 
      (eql (my-syntax-class next-char) ?s)) 
      ) 
     (return)) 
     ) 
     (setq count (1- count))))) 

(defun delete-word (&optional arg) 
    "Delete characters forward until encountering the end of a word. 
With argument ARG, do this that many times." 
    (interactive "p") 
    (delete-region (point) (progn (my-forward-word arg) (point)))) 

(defun backward-delete-word (arg) 
    "Delete characters backward until encountering the beginning of a word. 
With argument ARG, do this that many times." 
    (interactive "p") 
    (delete-word (- arg))) 

(defun my-backward-word (&optional arg) 
    (interactive "^p") 
    (or arg (setq arg 1)) 
    (my-forward-word (- arg))) 

(global-set-key (kbd "C-<left>") 'my-backward-word) 
(global-set-key (kbd "C-<right>") 'my-forward-word) 
(global-set-key (kbd "C-<delete>") 'delete-word) 
(global-set-key (kbd "C-<backspace>") 'backward-delete-word)