謝謝,德魯。
事實證明,區域最接近我所需要的,雖然冰柱和isearch +也是有用的。
至於區域,事實證明它的zz-zones-complement函數似乎沒有返回正確的信息。
但是,我寫了自己的函數,我可以使用它的位置。
我現在這樣做是爲了運行在所有先前通過zones.el添加的區域的補任意Lisp代碼...
(defun my-complement-zones (&optional zones)
(unless zones
(setq zones zz-izones))
(zz-unite-zones 'zones)
(let ((result())
(end (copy-marker (point-min)))
(n 0)
(a nil)
(b nil))
(dolist (item (reverse zones))
(setq n (1+ n))
(setq a (cadr item))
(setq b (caddr item))
(setq result (append (list (list n end a)) result))
(setq end b))
(when (< (marker-position end) (point-max))
(setq result (append (list (list (1+ n) end (copy-marker (point-max)))) result)))
result))
;; Each element has three values: an index followed by the start
;; and end markers for each region. To traverse this structure,
;; do the following ...
(dolist (region (my-complement-zones))
(let ((idx (car region))
(start (cadr region))
(end (caddr region)))
;; At this point, "start" is a marker pointing to the
;; beginning of the given zone, and "end" is a marker pointing
;; its endpoint. I can use these for inputs to any region-aware
;; elisp commands, or for any functions that I might want to
;; write which operate on each given region.
;;
;; ... etc. ...
))
...這是我寫這將穿越功能一個區域列表並將lambda應用於每個區域。它的工作原理等同,無論我們使用原來的ZZ-izones或它的互補與我的函數生成:
;; Helper function
(defun funcallable (func)
(and func
(or (functionp func)
(and (symbolp func)
(fboundp func)))))
;; Traverse a list of zones such as zz-izones, and apply a lambda
;; to each zone in the list. Works equivalently with the output of
;; `my-complement-zones'.
(defun traverse-zones (func &optional zones)
(when (funcallable func)
(unless zones
(setq zones zz-izones))
(zz-unite-zones 'zones) ;; not sure if this is really necessary
(dolist (zone zones)
(let ((i (car zone))
(s (cadr zone))
(e (caddr zone)))
(funcall func i s e)))))
爲了說明ZZ-izones和ZZ-區補的輸出之間結構上的差異,這裏有一個ZZ-izones結構我在一個名爲「foo」的緩衝區中創建的例子:
((4 #<marker at 1202 in foo> #<marker at 1266 in foo>) (3 #<marker at 689 in foo> #<marker at 1132 in foo>) (2 #<marker at 506 in foo> #<marker at 530 in foo>) (1 #<marker at 3 in foo> #<marker at 446 in foo>))
這裏是(ZZ-區補ZZ-izones)看起來像這個一樣ZZ-izones列表...
((1 4) (#<marker at 1202 in foo> 3) (#<marker at 689 in foo> 2) (#<marker at 506 in foo> 1) (#<marker at 3 in foo> 1266)
請注意,zz-izones中的每個條目都包含一個索引和兩個標記。但是,在補充中,每個條目是兩個整數或一個標記和一個整數。這些結構不是同構的。
附加信息
對於(zz-zone-union (zz-izone-limits zz-izones nil t))
...
((#<marker at 3 in foo> #<marker at 446 in foo>) (#<marker at 506 in foo> #<marker at 530 in foo>) (#<marker at 689 in foo> #<marker at 1132 in foo>) (#<marker at 1202 in foo> #<marker at 1266 in foo>)
對於(zz-zones-complement (zz-zone-union (zz-izone-limits zz-izones nil t)))
((1 #<marker at 3 in foo>) (#<marker at 446 in foo> #<marker at 506 in foo>) (#<marker at 530 in foo> #<marker at 689 in foo>) (#<marker at 1132 in foo> #<marker at 1202 in foo>) (#<marker at 1266 in foo> 1266))
我想,如果我轉換 「1」 中的第一個條目我可以用這個補(copy-marker (point-min))
和最終項目中的「1266」到(copy-marker (point-max))
......除非我正在處理一個具體的案例,無論我是否d用標記或點來標記。
標記是理想的,因爲然後我可以在生成補碼後更改緩衝區,並且我不必擔心補語結構中的數字點值不再指向它最初指向的位置。
我們的帖子交叉了 - 您在輸入我的信息時發佈了關於['zones.el'](http://www.emacswiki.org/emacs/zones.el)的答案。 ;-) – Drew
謝謝你的這一切。但是,我仍然有另一個問題。你寫道:「基本區域只有限制,而不是標識符,函數zz-zones-complement返回一個基本區域列表」。我明白那個。那麼,如果不是zz-izones結構本身,我應該通過zz-zone來補充什麼?換句話說,在給定當前zz-izones結構的情況下,如何獲得「基本區域」列表?同樣,我的目標是這樣的:我想使用「正常」區域的結構和同構的補充區域。 – HippoMan
請參閱下面我剛添加的我的「其他信息」部分。 – HippoMan