2016-12-21 10 views
0

私は、XML-種類-のテキストElisp:単語リストを検索し、結果を別のバッファにコピーするにはどうすればいいですか?

<p>Hoc templum magnum est.</p> 
<p>Templa Romanorum magna sunt.</p> 
<p>Claudia haec templa in foro videt.</p> 

私はワードリスト「dempron」を検索しに単語リストから単語を持って文章をコピーしたいを持っているワードリスト

dempron {hic, haec, hoc, huius, huic, hunc, hanc, hac, hi, hae, horum, harum, his, hos, has} 

を持っていますという結果のバッファーはとなります。

+0

この問題についてご自身でお試しください。 Stackoverflowは、特定のプログラミングの問題ではなく、人々が無料でコードを書くサイトではありません。 –

+0

私はStackoverflowを乱用する意図はありませんでした。 他の人にはcharliegreenのコードが役立つことを願っています。 –

答えて

0

私はSimon Frommeに同意しますが、うまくいけばこれが始まります。ご質問がある場合はお知らせください。

(defconst dempron 
    '("hic" "haec" "hoc" "huius" "huic" "hunc" "hanc" "hac" "hi" "hae" "horum" 
    "harum" "his" "hos" "has")) 

(defun dempron-search() 
    "A function to naively search for sentences in XML <p> tags 
containing words from `dempron'. Run this in the buffer you want 
to search, and it will search from POINT onwards, writing results 
to a buffer called 'results'." 
    (interactive) 
    (beginning-of-line) 

    (while (not (eobp)) ;; while we're not at the end of the buffer 
    (let ((cur-line ;; get the current line as a string 
      (buffer-substring-no-properties 
      (progn (beginning-of-line) (point)) 
      (progn (end-of-line) (point))))) 

     ;; See if our current line is in a <p> tag (and run `string-match' so we 
     ;; can extract the sentence with `match-string') 
     (if (string-match "^<p>\\(.*\\)</p>$" cur-line) 
     (progn 
     ;; then extract the actual sentence with `match-string' 
     (setq cur-line (match-string 1 cur-line)) 

     ;; For each word in our sentence... (split on whitespace and 
     ;; anything the sentence is likely to end with) 
     (dolist (word (split-string cur-line "[[:space:].?!\"]+")) 
      ;; `downcase' to make our search case-insensitive 
      (if (member (downcase word) dempron) 
       ;; We have a match! Temporarily switch to the 
       ;; results buffer and write the sentence 
       (with-current-buffer (get-buffer-create "results") 
       (insert cur-line "\n"))))))) 
    (forward-line 1))) ;; Move to the next line 
+0

コードの宝庫に感謝します。それは素晴らしい 作品と私は間違いなく始めた。 –

関連する問題