0

を呼び出して取得した文字列を取得しましたbuffer-substring。設定に基づいて、この文字列からテキストを削除する方法はありfaceますか? ランダムな例として:

(save-excursion 
  (let ((end (point)))
(ignore-errors 
  (while (not (looking-at "[^][ \t\r\n(){}]+:"))
    (backward-sexp)))

SO がそれを強調表示する方法はわかりませんが、Emacs ではsave-excursion、 、letignore-errorsおよびwhileがすべてキーワードとして強調表示され、への正規表現引数がlooking-at文字列として強調表示されます。の戻り値はbuffer-substring次のようになります

#("    (save-excursion 
      (let ((end (point)))
    (ignore-errors 
      (while (not (looking-at \"[^][ \\t\\r\\n(){}]+:\"))
        (backward-sexp)))" 0 5 (fontified t) 5 19 (fontified t face font-lock-keyword-face) 19 28 (fontified t) 28 31 (fontified t face font-lock-keyword-face) 31 50 (fontified t) 50 63 (fontified t face font-lock-keyword-face) 63 65 (fontified t) 65 69 (fontified t) 69 74 (fontified t face font-lock-keyword-face) 74 75 (fontified t) 75 92 (fontified t) 92 94 (fontified t face font-lock-string-face) 94 95 (fontified t face (font-lock-negation-char-face font-lock-string-face)) 95 112 (fontified t face font-lock-string-face) 112 115 (fontified t) 115 137 (fontified t))

その例の文字列を考えると、face font-lock-keyword-face? つまり、次のようなことができるようにしたい

(foo-bar *that-region* 'font-lock-keyword-face)

そして返してもらう

(
  ( ((end (point)))
( 
  ( (not (looking-at "[^][ \t\r\n(){}]+:"))
    (backward-sexp)))
4

1 に答える 1

2

text-property-any問題のある面の開始点と終了点を見つけるためにを使用する必要がありtext-property-not-allます。次に、反復する必要があります。

(defun kill-text-with-property (start end property value &optional object)
  "Delete the text with the PROPERTY in the part of OBJECT from START and END."
  (interactive "r\nsProperty: \nsValue: ")
  (let ((delenda ()) (here start))
    ;; collect the list of regions to kill
    ;; note that delenda contains the regions in the reverse order so that
    ;; deleting the later ones do not affect the boundaries of the ealier ones
    (while (< here end)
      (let ((beg (text-property-any here end property value object))
            (stop (and beg (text-property-not-all beg end property value object) end)))
        (if (null beg)
            (setq here end)     ; done
          (push (cons beg stop) delenda)
          (setq here stop))))
    (if (stringp object)
        ;; collect the complements of delenda into a new string
        (....)
      ;; buffer: kill the delenda regions
      (with-current-buffer (or object (current-buffer))
        (dolist (pair delenda)
          (kill-region (car pair) (cdr pair)))))))
于 2013-08-01T17:02:17.690 に答える