2012-07-24 48 views
2

我有一個文本文件,其中包含相關的內容/段落。假設我從文本中剪切/殺死段落A.我想寫一個在這種情況下調用的函數,因此相關的段落 - 比方說B - 也被刪除。一個很好的例子就是一個包含引用/引用的文檔。 - 即每當你刪除文本的引文也被刪除 - 就像MS Office所做的一樣。從理論上講,我認爲:(基本)Elisp編程:Emacs的Cut函數的特殊鉤子

1)我需要切鉤 - 我無法找到合適的鉤子到目前爲止 2)用正則表達式可能是搜索功能 - 找到相關的文字 3)刪除文本

你能告訴我如何繼續?提示每一步或等

+0

這個問題有一些有吸引力的鉤子提示:http://stackoverflow.com/questions/8983758/in-post-command-hook-this-command-for-kill-word-has-turned-into-kill-region- som – tripleee 2012-08-02 07:51:20

回答

2

它很容易編寫功能這樣的病例:

(defun when-one-kill-one-and-three() 
    "If a buffer has a string \"one\", it deletes it. 
If in this buffer exists also a string \"three\", it will be killed afterwards. " 
    (interactive "*") 
    (save-excursion 
    (save-restriction 
     (widen) 
     (goto-char (point-min)) 
     (while (search-forward "one" nil t 1) 
     (kill-region (match-beginning 0) (match-end 0)) 
     (when (search-forward "three") 
      (kill-region (match-beginning 0) (match-end 0))))))) 
+0

非常棒的人,非常感謝! – Daniel 2012-07-24 16:32:02

1

1)我不認爲這是對切掛鉤,但你可以勸告切割(defadvice ..)

2)你應該以某種方式標記文本,並發現它與搜索(把一個號碼,以便您搜索)..

3)要刪除文本,你可以使用kill區域我想