aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Pierre Courtieu <courtieu@lri.fr>2005-02-21 17:35:29 +0000
committerGravatar Pierre Courtieu <courtieu@lri.fr>2005-02-21 17:35:29 +0000
commit82a8f92d05d54dcfe11f8c8ce3142733c674394f (patch)
tree87e9d82dc1c58b2f520824f6f5ee5552ead61194 /lib
parent1897272416f8276b52f551ac7e64bafb23452479 (diff)
Cleaning file holes.el (tab-width, docstring etc).
Diffstat (limited to 'lib')
-rw-r--r--lib/holes.el591
1 files changed, 302 insertions, 289 deletions
diff --git a/lib/holes.el b/lib/holes.el
index cdb6961a..d0c686d4 100644
--- a/lib/holes.el
+++ b/lib/holes.el
@@ -30,7 +30,7 @@
;;; Help:
(defvar holes-doc nil
- "The mode `holes-mode' is meant to help program editing.
+ "The mode `holes-mode' is meant to help program editing.
It is useful to build complicated expressions by copy pasting several
peaces of text from different parts of a buffer (or even from
different buffers).
@@ -46,7 +46,7 @@ any other characters.
USE
At any time only one particular hole, called \"active\", can be
-\"filled\". Holes can be in several buffers but there is always one or
+\"filled\". Holes can be in several buffers but there is always one or
zero active hole globally. It is highlighted with a different color.
Functions described below have default shortcuts when `holes-mode' is
@@ -58,9 +58,9 @@ TO DEFINE A HOLE, two methods:
\\[holes-set-make-active-hole]. If the selected region is empty,
then a hole containing # is created at point.
- o Select text with mouse while pressing `C-M'. If the selected
- region is empty (i.e. if you just click while pressing ctrl+meta),
- then a hole containing # is created.
+ o Select text with mouse while pressing ctrl and meta (`C-M-select').
+ If the selected region is empty (i.e. if you just click while
+ pressing ctrl+meta), then a hole containing # is created.
TO ACTIVATE A HOLE, click on it with the button 1 of your mouse. The
previous active hole will be deactivated.
@@ -77,7 +77,8 @@ then two methods:
o Select text with keyboard or mouse and hit
\\[holes-replace-update-active-hole]
- o Select text with mouse while pressing `C-M-S'. This is a
+ o Select text with mouse while pressing ctrl, meta and shift
+ (`C-M-S-select'). This is a
generalization of the `mouse-track-insert' feature of XEmacs. This
method allows to fill different holes faster than with the usual
copy-paste method.
@@ -87,15 +88,15 @@ can fill it immediately by hitting again
\\[holes-replace-update-active-hole] or `C-M-S-select'.
TO JUMP TO THE ACTIVE HOLE, just hit
-\\[holes-set-point-next-hole-destroy]. You must
-be in the buffer containing the active hole. the point will move to
+\\[holes-set-point-next-hole-destroy]. You must
+be in the buffer containing the active hole. the point will move to
the active hole, and the active hole will be destroyed so you can type
-something to put at its place. The following hole is automatically
+something to put at its place. The following hole is automatically
made active, so you can hit \\[holes-set-point-next-hole-destroy]
again.
-It is useful in combination with abbreviations. For example in
-coq-mode \"fix\" is an abbreviation for Fixpoint # (# : #) {struct #} :
+It is useful in combination with abbreviations. For example in
+`coq-mode' \"fix\" is an abbreviation for Fixpoint # (# : #) {struct #} :
# := #, where each # is a hole. Then hitting
\\[holes-set-point-next-hole-destroy] goes from one hole to the
following and you can fill-in each hole very quickly.
@@ -112,28 +113,26 @@ it mean anyway?)
holes, and undoing on holes cannot make holes re-appear. With Xemacs
it will, but if you copy paste the active hole, you will get several
holes highlighted as the active one (whereas only one of them really
-is), which is annoying
-
-")
+is), which is annoying")
;;; Code:
(cond
((string-match "NU Emacs" (emacs-version))
- ;;Pierre: should do almost what region-exists-p does in xemacs
+ ;;Pierre: should do almost what region-exists-p does in xemacs
(defmacro holes-region-exists-p nil
- "Returns t if the mark is active, nil otherwise."
- `(not (eq mark-active nil)))
- (defmacro holes-get-selection nil "see current-kill"
- '(current-kill 0))))
+ "Returns t if the mark is active, nil otherwise."
+ `(not (eq mark-active nil)))
+ (defmacro holes-get-selection nil "see current-kill"
+ '(current-kill 0))))
(cond
((string-match "XEmacs" (emacs-version))
(defmacro holes-region-exists-p nil "see region-exists-p"
- '(region-exists-p))
- (defmacro holes-get-selection nil "see get-selection"
- '(get-selection))))
+ '(region-exists-p))
+ (defmacro holes-get-selection nil "see get-selection"
+ '(get-selection))))
;;; initialization
@@ -157,7 +156,15 @@ every hole.")
"String to be inserted for empty hole (don't put an empty string).")
(defcustom holes-empty-hole-regexp "#\\|\\(@{\\)\\([^{}]*\\)\\(}\\)"
- "Regexp denoting a hole in abbrevs. Must match either `holes-empty-hole-string' or a regexp formed by three consecutive groups (i.e. \\\\(...\\\\) ) (other groups must be shy (i.e. \\\\(?:...\\\\))), denoting the exact limits of the hole (the middle group), the opening and closing delimiters of the hole (first and third groups) which will be deleted after abbrev expand. For example: \"#\\|\\(@{\\)\\([^{}]*\\)\\(}\\)\" matches any # or @{text} but in the second case the abbrev expand will be a hole containing text without brackets.")
+ "Regexp denoting a hole in abbrevs.
+Must match either `holes-empty-hole-string' or a regexp formed by
+three consecutive groups (i.e. \\\\(...\\\\) ) (other groups must be
+shy (i.e. \\\\(?:...\\\\))), denoting the exact limits of the hole
+(the middle group), the opening and closing delimiters of the hole
+(first and third groups) which will be deleted after abbrev expand.
+For example: \"#\\|\\(@{\\)\\([^{}]*\\)\\(}\\)\" matches any # or
+@{text} but in the second case the abbrev expand will be a hole
+containing text without brackets.")
(defcustom holes-search-limit 1000
"Number of chars to look forward when looking for the next hole, unused for now.") ;unused for the moment
@@ -173,21 +180,25 @@ every hole.")
(defface active-hole-face
'((((class grayscale) (background light)) (:background "dimgrey"))
- (((class grayscale) (background dark)) (:background "LightGray"))
- (((class color) (background dark)) (:background "darkred") (:foreground "white"))
- (((class color) (background light)) (:background "paleVioletRed" (:foreground "black")))
- ;??(t (:background t))
- )
+ (((class grayscale) (background dark)) (:background "LightGray"))
+ (((class color) (background dark))
+ (:background "darkred") (:foreground "white"))
+ (((class color) (background light))
+ (:background "paleVioletRed" (:foreground "black")))
+ ;;??(t (:background t))
+ )
"Font Lock face used to highlight the active hole."
)
(defface inactive-hole-face
'((((class grayscale) (background light)) (:background "lightgrey"))
- (((class grayscale) (background dark)) (:background "Grey"))
- (((class color) (background dark)) (:background "mediumblue") (:foreground "white"))
- (((class color) (background light)) (:background "lightsteelblue" (:foreground "black")))
- ;??(t (:background t))
- )
+ (((class grayscale) (background dark)) (:background "Grey"))
+ (((class color) (background dark))
+ (:background "mediumblue") (:foreground "white"))
+ (((class color) (background light))
+ (:background "lightsteelblue" (:foreground "black")))
+ ;;??(t (:background t))
+ )
"Font Lock face used to highlight the active hole."
)
@@ -212,27 +223,27 @@ every hole.")
)
(defun holes-is-hole-p (SPAN)
- ; checkdoc-params: (SPAN)
+ ; checkdoc-params: (SPAN)
"Internal."
(span-property SPAN 'hole)
)
(defun holes-hole-start-position (HOLE)
- ; checkdoc-params: (HOLE)
+ ; checkdoc-params: (HOLE)
"Internal."
(assert (holes-is-hole-p HOLE) t "holes-hole-start-position: given span is not a hole")
(span-start HOLE)
)
(defun holes-hole-end-position (HOLE)
- ; checkdoc-params: (HOLE)
+ ; checkdoc-params: (HOLE)
"Internal."
(assert (holes-is-hole-p HOLE) t "holes-hole-end-position:given span is not a hole")
(span-end HOLE)
)
(defun holes-hole-buffer (HOLE)
- ; checkdoc-params: (HOLE)
+ ; checkdoc-params: (HOLE)
"Internal."
(assert (holes-is-hole-p HOLE) t "holes-hole-buffer: given span is not a hole")
(span-buffer HOLE)
@@ -250,8 +261,8 @@ If pos is not in a hole raises an error."
(defun holes-active-hole-exist-p ()
"Return t if the active hole exists and is not empty (ie detached).
-Use this to know if the active hole is set and
- usable (don't use the active-hole-marker variable)."
+Use this to know if the active hole is set and usable (don't use the
+active-hole-marker variable)."
(not (span-detached-p holes-active-hole))
)
@@ -263,7 +274,7 @@ See `active-hole-buffer' to get its buffer. Returns an error if
active hole doesn't exist (the marker is set to nothing)."
(assert (holes-active-hole-exist-p) t
- "holes-active-hole-start-position: no active hole")
+ "holes-active-hole-start-position: no active hole")
(holes-hole-start-position holes-active-hole)
)
@@ -273,7 +284,7 @@ See `active-hole-buffer' to get its buffer. Returns an error if
active hole doesn't exist (the marker is set to nothing)."
(assert (holes-active-hole-exist-p) t
- "holes-active-hole-end-position: no active hole")
+ "holes-active-hole-end-position: no active hole")
(holes-hole-end-position holes-active-hole)
)
@@ -285,7 +296,7 @@ Raise an error if the active hole is not set. Don't care if the
active hole is empty."
(assert (holes-active-hole-exist-p) t
- "holes-active-hole-buffer: no active hole")
+ "holes-active-hole-buffer: no active hole")
(holes-hole-buffer holes-active-hole)
)
@@ -296,7 +307,7 @@ Raises an error if active-hole is not set."
(interactive)
(assert (holes-active-hole-exist-p) t
- "holes-goto-active-hole: no active hole")
+ "holes-goto-active-hole: no active hole")
(goto-char (holes-active-hole-start-position))
)
@@ -307,7 +318,7 @@ DON'T USE this as it would break synchronization (non active hole
highlighted)."
(assert (holes-is-hole-p HOLE) t
- "holes-highlight-hole-as-active: given span is not a hole")
+ "holes-highlight-hole-as-active: given span is not a hole")
(set-span-face HOLE 'active-hole-face)
)
@@ -317,7 +328,7 @@ DON'T USE this as it would break synchronization (active hole non
highlighted)."
(assert (holes-is-hole-p HOLE) t
- "holes-highlight-hole: given span is not a hole %S" HOLE)
+ "holes-highlight-hole: given span is not a hole %S" HOLE)
(set-span-face HOLE 'inactive-hole-face)
)
@@ -329,10 +340,10 @@ the active hole is already disable."
(if (not (holes-active-hole-exist-p))
()
- ;; HACK: normal hole color, this way undo will show this hole
- ;; normally and not as active hole. Ideally, undo should restore
- ;; the active hole, but it doesn't, so we put the 'not active'
- ;; color
+ ;; HACK: normal hole color, this way undo will show this hole
+ ;; normally and not as active hole. Ideally, undo should restore
+ ;; the active hole, but it doesn't, so we put the 'not active'
+ ;; color
(holes-highlight-hole holes-active-hole)
(setq holes-active-hole holes-default-hole)
)
@@ -346,7 +357,7 @@ the active hole is already disable."
Error if HOLE is not a hole."
(assert (holes-is-hole-p HOLE) t
- "holes-set-active-hole: given span is not a hole")
+ "holes-set-active-hole: given span is not a hole")
(if (holes-active-hole-exist-p) (holes-highlight-hole holes-active-hole))
(setq holes-active-hole HOLE)
(holes-highlight-hole-as-active holes-active-hole)
@@ -365,21 +376,21 @@ Error if HOLE is not a hole."
(let ((ext (make-span start end)))
(set-span-properties
ext `(
- hole ,holes-counter
- mouse-face highlight
- priority 100 ;; what should I put here? I want big priority
- face secondary-selection
- start-open nil
- end-open t
- duplicable t
- ;; unique t
- ;; really disappear if empty:
- evaporate t ;; Emacs
- detachable t ;; XEmacs
- ;; pointer frame-icon-glyph
- help-echo "this is a \"hole\", button 2 to forget, button 3 to destroy, button 1 to make active"
- 'balloon-help "this is a \"hole\", button 2 to forget, button 3 to destroy, button 1 to make active"
- ))
+ hole ,holes-counter
+ mouse-face highlight
+ priority 100;; what should I put here? I want big priority
+ face secondary-selection
+ start-open nil
+ end-open t
+ duplicable t
+ ;; unique t
+ ;; really disappear if empty:
+ evaporate t;; Emacs
+ detachable t;; XEmacs
+ ;; pointer frame-icon-glyph
+ help-echo "this is a \"hole\", button 2 to forget, button 3 to destroy, button 1 to make active"
+ 'balloon-help "this is a \"hole\", button 2 to forget, button 3 to destroy, button 1 to make active"
+ ))
(set-span-keymap ext hole-map)
(setq holes-counter (+ holes-counter 1))
@@ -394,12 +405,12 @@ the span."
(interactive)
(let* ((rstart (or start (holes-region-beginning-or-nil) (point)))
- (rend (or end (holes-region-end-or-nil) (point))))
+ (rend (or end (holes-region-end-or-nil) (point))))
(if (eq rstart rend)
- (progn
- (insert-string holes-empty-hole-string)
- (setq rend (point))
- )
+ (progn
+ (insert-string holes-empty-hole-string)
+ (setq rend (point))
+ )
)
(holes-make-hole rstart rend)
)
@@ -407,10 +418,10 @@ the span."
(defun holes-clear-hole (HOLE)
- ; checkdoc-params: (HOLE)
+ ; checkdoc-params: (HOLE)
"Internal."
(assert (holes-is-hole-p HOLE) t
- "holes-clear-hole: given span is not a hole")
+ "holes-clear-hole: given span is not a hole")
(if (and (holes-active-hole-exist-p) (eq holes-active-hole HOLE))
(holes-disable-active-hole)
@@ -419,16 +430,16 @@ the span."
)
(defun holes-clear-hole-at (&optional pos)
- "Clears hole at POS (default=point)."
+ "Clear hole at POS (default=point)."
(interactive)
(if (not (holes-is-in-hole-p (or pos (point))))
- (error "Holes-clear-hole-at: no hole here"))
+ (error "Holes-clear-hole-at: no hole here"))
(holes-clear-hole (holes-hole-at (or pos (point))))
)
(defun holes-map-holes (FUNCTION &optional OBJECT FROM TO)
- ; checkdoc-params: (FUNCTION OBJECT FROM TO)
+ ; checkdoc-params: (FUNCTION OBJECT FROM TO)
"Internal."
(fold-spans FUNCTION OBJECT FROM TO nil nil 'hole)
)
@@ -436,13 +447,13 @@ the span."
(defun holes-mapcar-holes (FUNCTION &optional FROM TO PROP)
- ; checkdoc-params: (FUNCTION FROM TO PROP)
+ ; checkdoc-params: (FUNCTION FROM TO PROP)
"Internal."
(mapcar-spans FUNCTION FROM TO 'hole)
)
(defun holes-clear-all-buffer-holes (&optional start end)
- "Clears all holes leaving their contents.
+ "Clear all holes leaving their contents.
Operate betwenn START and END if non nil."
(interactive)
(holes-disable-active-hole)
@@ -462,9 +473,9 @@ hole found, return nil."
(defun holes-next-after-active-hole ()
"Internal."
(assert (holes-active-hole-exist-p) t
- "next-active-hole: no active hole")
+ "next-active-hole: no active hole")
(holes-next (holes-active-hole-end-position)
- (holes-active-hole-buffer))
+ (holes-active-hole-buffer))
)
(defun holes-set-active-hole-next (&optional BUFFER pos)
@@ -472,23 +483,23 @@ hole found, return nil."
Default pos = point and buffer = current."
(interactive)
(let ((nxthole (holes-next (or pos (point))
- (or BUFFER (current-buffer)))))
+ (or BUFFER (current-buffer)))))
(if nxthole
- (progn
- (holes-set-active-hole nxthole)
- )
- (holes-disable-active-hole)
+ (progn
+ (holes-set-active-hole nxthole)
+ )
+ (holes-disable-active-hole)
)
)
)
;;;(defun holes-set-active-hole-next-after-active ()
-;;; "sets the active hole to the first hole after active
-;;; hole.";;;;
+;; "sets the active hole to the first hole after active
+;; hole.";;;;
;;; (interactive)
-;;; (holes-next-after-active-hole)
-;;;)
+;; (holes-next-after-active-hole)
+;;)
@@ -508,36 +519,34 @@ Shift markers. optionnal argument BUFFER specifies in which buffer."
(defun holes-replace (str &optional thehole)
- "Replace thehole by STR.
-(THEHOLE defaults to the active hole) (str
-was optionnal but not anymore), do not use this, it breaks the right
-colorization of the active goal(FIXME?). Use `replace-active-hole'
-instead."
+ "Replace the current hole by STR, replace THEHOLE instead if given.
+Do not use this, it breaks the right colorization of the active
+goal(FIXME?). Use `replace-active-hole' instead."
(if (and (not thehole)
(not (holes-active-hole-exist-p)))
(error "No hole to fill")
- ;; defensive: replacing the hole should make it detached and
- ;; therefore inexistent. other reason: this is a hack: unhighlight
- ;; so that undo wont show it highlighted)
- (if (and (holes-active-hole-exist-p)
- thehole
- (eq holes-active-hole thehole))
- (holes-disable-active-hole)
- )
- (let ((exthole (or thehole holes-active-hole)))
+ ;; defensive: replacing the hole should make it detached and
+ ;; therefore inexistent. other reason: this is a hack: unhighlight
+ ;; so that undo wont show it highlighted)
+ (if (and (holes-active-hole-exist-p)
+ thehole
+ (eq holes-active-hole thehole))
+ (holes-disable-active-hole)
+ )
+ (let ((exthole (or thehole holes-active-hole)))
(holes-replace-segment (holes-hole-start-position exthole)
- (holes-hole-end-position exthole)
- (or str (car kill-ring)) ;kill ring?
- (span-buffer exthole)
- )
- (detach-span exthole) ;; this seems necessary for span overlays,
- ;; where the buffer attached to the span is
- ;; not removed automatically by the fact
- ;; that the span is removed from the buffer
- ;; (holes-replace-segment should perhaps
- ;; take care of that)
- )
- )
+ (holes-hole-end-position exthole)
+ (or str (car kill-ring)) ;kill ring?
+ (span-buffer exthole)
+ )
+ (detach-span exthole);; this seems necessary for span overlays,
+ ;; where the buffer attached to the span is
+ ;; not removed automatically by the fact
+ ;; that the span is removed from the buffer
+ ;; (holes-replace-segment should perhaps
+ ;; take care of that)
+ )
+ )
)
(defun holes-replace-active-hole (&optional str)
@@ -555,16 +564,16 @@ Like `holes-replace-active-hole', but then sets the active hole to the
following hole if it exists."
(interactive)
(assert (holes-active-hole-exist-p) t
- "holes-replace-update-active-hole: no active hole")
+ "holes-replace-update-active-hole: no active hole")
(if (not (holes-active-hole-exist-p))
()
(let ((nxthole (holes-next-after-active-hole)))
(holes-replace-active-hole
(or str
- (and (holes-region-exists-p) (holes-copy-active-region))
- (holes-get-selection) (error "Nothing to put in hole")))
+ (and (holes-region-exists-p) (holes-copy-active-region))
+ (holes-get-selection) (error "Nothing to put in hole")))
(if nxthole (holes-set-active-hole nxthole)
- (setq holes-active-hole holes-default-hole))
+ (setq holes-active-hole holes-default-hole))
)
)
)
@@ -586,91 +595,91 @@ Sets `holes-active-hole' to the next hole if it exists."
;;; mouse stuff, I want to make something close to `mouse-track-insert'
-;;; of Xemacs, but with modifier ctrl-meta and ctrl-meta-shift
+;; of Xemacs, but with modifier ctrl-meta and ctrl-meta-shift
;;; Emacs and Xemacs have different ways of dealing with mouse
-;;; selection, but `mouse-track'(Xemacs) mouse-drag-region(Emacs)
-;;; have nearly the same meaning for me. So I define this
-;;; track-mouse-selection.
+;; selection, but `mouse-track'(Xemacs) mouse-drag-region(Emacs)
+;; have nearly the same meaning for me. So I define this
+;; track-mouse-selection.
(eval-and-compile
- (cond
- ((fboundp 'mouse-track)
- (defsubst holes-track-mouse-selection (event)"see `mouse-track'"
- (mouse-track event)))
- ((fboundp 'mouse-drag-region)
- (defsubst holes-track-mouse-selection (event)
- "see `mouse-drag-region'"
- (mouse-drag-region event)))
- (t
- (error
- "Your (X)Emacs version is not compatible with holes (too old or
+ (cond
+ ((fboundp 'mouse-track)
+ (defsubst holes-track-mouse-selection (event)"see `mouse-track'"
+ (mouse-track event)))
+ ((fboundp 'mouse-drag-region)
+ (defsubst holes-track-mouse-selection (event)
+ "see `mouse-drag-region'"
+ (mouse-drag-region event)))
+ (t
+ (error
+ "Your (X)Emacs version is not compatible with holes (too old or
new version?), sorry"))
+ )
)
- )
;;; number of clicks for emacs and xemacs
(eval-and-compile
- (cond
- ((fboundp 'mouse-track)
- (defsubst holes-track-mouse-clicks ()
- "see `mouse-track-click-count'"
- mouse-track-click-count))
- ((fboundp 'mouse-drag-region)
- (defsubst holes-track-mouse-clicks ()
- "see `mouse-selection-click-count'"
- (+ mouse-selection-click-count 1)))
- (t
- (error
- "Your (X)Emacs version is not compatible with holes (too old or
+ (cond
+ ((fboundp 'mouse-track)
+ (defsubst holes-track-mouse-clicks ()
+ "see `mouse-track-click-count'"
+ mouse-track-click-count))
+ ((fboundp 'mouse-drag-region)
+ (defsubst holes-track-mouse-clicks ()
+ "see `mouse-selection-click-count'"
+ (+ mouse-selection-click-count 1)))
+ (t
+ (error
+ "Your (X)Emacs version is not compatible with holes (too old or
new version?), sorry"))
+ )
)
- )
(defun holes-mouse-replace-active-hole (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
(interactive "*e")
(holes-track-mouse-selection event)
(save-excursion
;;HACK: nothing if one click (but a second is perhaps coming)
(if (and (eq (holes-track-mouse-clicks) 1)
- (not (holes-region-exists-p)))
- ()
+ (not (holes-region-exists-p)))
+ ()
(if (not (holes-region-exists-p))
- (error "Nothing to put in hole")
- (holes-replace-update-active-hole (holes-get-selection))
- (message "hole replaced")
- )
+ (error "Nothing to put in hole")
+ (holes-replace-update-active-hole (holes-get-selection))
+ (message "hole replaced")
+ )
)
)
; (zmacs-deactivate-region)
)
(defun holes-destroy-hole (&optional SPAN)
- ; checkdoc-params: (SPAN)
+ ; checkdoc-params: (SPAN)
"Internal."
(interactive)
(let* ((sp (or SPAN (holes-hole-at (point)) (error "No hole to destroy"))))
- (save-excursion
- (if (and (holes-active-hole-exist-p)
- (eq sp holes-active-hole))
- (holes-disable-active-hole))
- (holes-replace "" sp)
- (detach-span sp)
- )
- (message "hole killed")
- )
+ (save-excursion
+ (if (and (holes-active-hole-exist-p)
+ (eq sp holes-active-hole))
+ (holes-disable-active-hole))
+ (holes-replace "" sp)
+ (detach-span sp)
+ )
+ (message "hole killed")
+ )
)
(defun holes-hole-at-event (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
- (span-at-event event 'hole))
+ (span-at-event event 'hole))
(defun holes-mouse-destroy-hole (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
(interactive "*e")
(holes-destroy-hole (holes-hole-at-event event))
@@ -678,15 +687,15 @@ Sets `holes-active-hole' to the next hole if it exists."
;;;(span-at-event EVENT &optional PROPERTY BEFORE AT-FLAG)
-;;;comprend pas??
+;;comprend pas??
(defun holes-mouse-forget-hole (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
(interactive "*e")
(save-excursion
(let ((ext (holes-hole-at-event event)))
(if (eq ext holes-active-hole)
- (holes-disable-active-hole))
+ (holes-disable-active-hole))
(detach-span ext)
)
)
@@ -696,29 +705,29 @@ Sets `holes-active-hole' to the next hole if it exists."
(defun holes-mouse-set-make-active-hole (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
(interactive "*e")
- ;;(set-mark (point))
+ ;;(set-mark (point))
(holes-track-mouse-selection event)
(if (and (eq (holes-track-mouse-clicks) 1)
- (not (holes-region-exists-p)))
- (holes-set-make-active-hole (point) (point))
-
- (if (holes-region-exists-p)
- (holes-set-make-active-hole)
- (let ((ext (holes-hole-at-event event)))
- (if (and ext (holes-is-hole-p ext))
- (error "Already a hole here")
- (holes-set-active-hole (holes-make-hole-at)))
- )
- )
- )
+ (not (holes-region-exists-p)))
+ (holes-set-make-active-hole (point) (point))
+
+ (if (holes-region-exists-p)
+ (holes-set-make-active-hole)
+ (let ((ext (holes-hole-at-event event)))
+ (if (and ext (holes-is-hole-p ext))
+ (error "Already a hole here")
+ (holes-set-active-hole (holes-make-hole-at)))
+ )
+ )
+ )
)
(defun holes-mouse-set-active-hole (event)
- ; checkdoc-params: (event)
+ ; checkdoc-params: (event)
"Internal."
(interactive "*e")
(let ((ext (holes-hole-at-event event)))
@@ -731,7 +740,7 @@ Sets `holes-active-hole' to the next hole if it exists."
(defun holes-set-point-next-hole-destroy ()
"Moves the point to current active hole (if any and if in current buffer).
- Destroy it and makes the next hole active if any."
+Destroy it and makes the next hole active if any."
(interactive)
(assert (holes-active-hole-exist-p) nil "no active hole")
(assert (eq (current-buffer) (holes-active-hole-buffer)) nil
@@ -758,19 +767,19 @@ Sets `holes-active-hole' to the next hole if it exists."
(define-key map [(mouse-2)] 'holes-mouse-forget-hole)))
map)
"Keymap to use on the holes's overlays.
- This keymap is used only when
+This keymap is used only when
on a hole. See `holes-mode-map' for the keymap of `holes-mode'.")
(defvar holes-mode-map
(let ((map (make-sparse-keymap)))
- (define-key map [(control c) (h)] 'holes-set-make-active-hole)
- (define-key map [(control c) (control y)] 'holes-replace-update-active-hole)
- (define-key map [(control meta down-mouse-1)] 'holes-mouse-set-make-active-hole)
- (define-key map [(control meta shift down-mouse-1)] 'holes-mouse-replace-active-hole)
- (define-key map [(meta return)] 'holes-set-point-next-hole-destroy)
+ (define-key map [(control c) (h)] 'holes-set-make-active-hole)
+ (define-key map [(control c) (control y)] 'holes-replace-update-active-hole)
+ (define-key map [(control meta down-mouse-1)] 'holes-mouse-set-make-active-hole)
+ (define-key map [(control meta shift down-mouse-1)] 'holes-mouse-replace-active-hole)
+ (define-key map [(meta return)] 'holes-set-point-next-hole-destroy)
map)
"Keymap of `holes-mode'.
- This is not the keymap used on holes's overlay
+This is not the keymap used on holes's overlay
(see `hole-map' instead). This one is active whenever we are on a
buffer where `holes-mode' is active.")
@@ -785,43 +794,43 @@ Sets `holes-active-hole' to the next hole if it exists."
;;;;;;;;;;; End Customizable key bindings ;;;;;
;;; utilities to be used in conjunction with abbrevs.
-;;; The idea is to put abbrevs of the form:
-;;;(define-abbrev-table 'tuareg-mode-abbrev-table
-;;; '(
-;;; ("l" "let # = # in" replace-#-after-abbrev2 0)
-;;; )
-;;; )
-;;; where replace-#-after-abbrev2 should be a function which replace the
-;;; two #'s (two occurences going backward from abbrev expantion point)
-;;; by holes and leave point at the first # (deleting
-;;; it). holes-set-point-next-hole-destroy allow to go to the next hole.
+;; The idea is to put abbrevs of the form:
+;;(define-abbrev-table 'tuareg-mode-abbrev-table
+;; '(
+;; ("l" "let # = # in" replace-#-after-abbrev2 0)
+;; )
+;; )
+;; where replace-#-after-abbrev2 should be a function which replace the
+;; two #'s (two occurences going backward from abbrev expantion point)
+;; by holes and leave point at the first # (deleting
+;; it). holes-set-point-next-hole-destroy allow to go to the next hole.
;;;following function allow to replace occurrences of a string by a
-;;;hole.
+;;hole.
;;;c must be a string of length 1
(defun holes-count-char-in-string (c str)
- ; checkdoc-params: (c str)
+ ; checkdoc-params: (c str)
"Internal."
(let ((cpt 0) (s str))
- (while (not (string-equal s ""))
- (if (string-equal (substring s 0 1) c) (setq cpt (+ cpt 1)))
- (setq s (substring s 1))
- )
- cpt
- )
+ (while (not (string-equal s ""))
+ (if (string-equal (substring s 0 1) c) (setq cpt (+ cpt 1)))
+ (setq s (substring s 1))
+ )
+ cpt
+ )
)
(defun holes-count-re-in-string (regexp str)
- ; checkdoc-params: (regexp str)
+ ; checkdoc-params: (regexp str)
"Internal."
(let ((cpt 0) (s str))
- (while (and (not (string-equal s "")) (string-match regexp s) )
- (setq cpt (+ cpt 1))
- (setq s (substring s (match-end 0)))
- )
- cpt
- )
+ (while (and (not (string-equal s "")) (string-match regexp s) )
+ (setq cpt (+ cpt 1))
+ (setq s (substring s (match-end 0)))
+ )
+ cpt
+ )
)
(defun holes-count-chars-in-last-expand ()
@@ -836,17 +845,17 @@ Sets `holes-active-hole' to the next hole if it exists."
(defun holes-indent-last-expand ()
"Indent last abbrev expansion.
- Must be called when the point is at end of last abbrev expansion."
+Must be called when the point is at end of last abbrev expansion."
(let ((n (holes-count-newlines-in-last-expand)))
- (save-excursion
- (previous-line n)
- (while (>= n 0)
- (funcall indent-line-function)
- (next-line 1)
- (setq n (- n 1))
- )
- )
- )
+ (save-excursion
+ (previous-line n)
+ (while (>= n 0)
+ (funcall indent-line-function)
+ (next-line 1)
+ (setq n (- n 1))
+ )
+ )
+ )
)
(defun holes-count-holes-in-last-expand ()
@@ -856,7 +865,7 @@ Sets `holes-active-hole' to the next hole if it exists."
(defun holes-replace-string-by-holes (start end str)
"Make holes of occurrence (between START and END) of STR.
- Sets the active hole to the last created hole and unsets it if no hole is
+Sets the active hole to the last created hole and unsets it if no hole is
created."
(interactive)
@@ -875,36 +884,36 @@ Sets `holes-active-hole' to the next hole if it exists."
(defun holes-replace-string-by-holes-backward (num regexp)
"Make NUM occurrences of REGEXP be holes looking backward.
- Sets the active hole to the last created hole and unsets it if no hole is
+Sets the active hole to the last created hole and unsets it if no hole is
created. Return t if num is > 0, nil otherwise."
(interactive)
(holes-disable-active-hole)
(if (<= num 0) nil
- (let* ((n num) (lgth 0))
- (save-excursion
- (while (> n 0)
- (progn
- (re-search-backward regexp)
- (if (string-equal (match-string 0) holes-empty-hole-string)
- (holes-make-hole (match-beginning 0) (match-end 0))
- (holes-make-hole (match-beginning 2) (match-end 2))
- (goto-char (match-beginning 3))
- (delete-char (length (match-string 3)))
- (goto-char (match-beginning 1))
- (delete-char (length (match-string 1))))
- (holes-set-active-hole-next)
- (setq n (- n 1)))
- )
- )
- t
- )
- )
+ (let* ((n num) (lgth 0))
+ (save-excursion
+ (while (> n 0)
+ (progn
+ (re-search-backward regexp)
+ (if (string-equal (match-string 0) holes-empty-hole-string)
+ (holes-make-hole (match-beginning 0) (match-end 0))
+ (holes-make-hole (match-beginning 2) (match-end 2))
+ (goto-char (match-beginning 3))
+ (delete-char (length (match-string 3)))
+ (goto-char (match-beginning 1))
+ (delete-char (length (match-string 1))))
+ (holes-set-active-hole-next)
+ (setq n (- n 1)))
+ )
+ )
+ t
+ )
+ )
)
(defun holes-replace-string-by-holes-move-point (start end str)
- ; checkdoc-params: (start end str)
+ ; checkdoc-params: (start end str)
"Internal."
(interactive)
@@ -913,60 +922,60 @@ Sets `holes-active-hole' to the next hole if it exists."
)
(defun holes-replace-string-by-holes-backward-move-point (num str)
- ; checkdoc-params: (num str)
+ ; checkdoc-params: (num str)
"Internal."
(interactive)
(and (holes-replace-string-by-holes-backward num str)
- t ;(holes-set-point-next-hole-destroy)
- )
+ t ;(holes-set-point-next-hole-destroy)
+ )
)
(defun holes-abbrev-complete ()
"Complete abbrev by putting holes and indenting.
- Moves point at beginning of expanded text. Put this function as
+Moves point at beginning of expanded text. Put this function as
call-back for your abbrevs, and just expanded \"#\" and \"@{..}\" will
become holes."
(let ((pos last-abbrev-location))
- (holes-indent-last-expand)
- (holes-replace-string-by-holes-backward-move-point
- (holes-count-holes-in-last-expand) holes-empty-hole-regexp)
- (if (> (holes-count-holes-in-last-expand) 1)
- (progn (goto-char pos)
- (message "Hit M-ret to jump to active hole. C-h holes-doc to see holes doc."))
-
- (if (= (holes-count-holes-in-last-expand) 0) () ; no hole, stay here.
- (goto-char pos)
- (holes-set-point-next-hole-destroy) ; if only one hole, go to it.
- )
- )
- )
+ (holes-indent-last-expand)
+ (holes-replace-string-by-holes-backward-move-point
+ (holes-count-holes-in-last-expand) holes-empty-hole-regexp)
+ (if (> (holes-count-holes-in-last-expand) 1)
+ (progn (goto-char pos)
+ (message "Hit M-ret to jump to active hole. C-h holes-doc to see holes doc."))
+
+ (if (= (holes-count-holes-in-last-expand) 0) () ; no hole, stay here.
+ (goto-char pos)
+ (holes-set-point-next-hole-destroy) ; if only one hole, go to it.
+ )
+ )
+ )
)
;;; insert the expansion of abbrev s, and replace #s by holes. It was
-;;; possible to implement it with a simple ((insert s) (expand-abbrev))
-;;; but undo would show the 2 steps, which is bad.
+;; possible to implement it with a simple ((insert s) (expand-abbrev))
+;; but undo would show the 2 steps, which is bad.
(defun holes-insert-and-expand (s)
"Insert S, expand it and replace #s and @{]s by holes."
(let* ((pos (point))
- (exp (abbrev-expansion s))
- (c (holes-count-re-in-string holes-empty-hole-regexp exp)))
- (insert exp)
- (holes-replace-string-by-holes-backward-move-point c holes-empty-hole-regexp)
- (if (> c 1) (goto-char pos)
- (goto-char pos)
- (holes-set-point-next-hole-destroy) ; if only one hole, go to it.
- )
- (if (> c 1) (message "Hit M-ret to jump to active hole. C-h holes-doc to see holes doc.")
- )
- )
- )
-
-(defvar holes-mode nil
- "Is equal to t if holes mode is on, nil otherwise.")
+ (exp (abbrev-expansion s))
+ (c (holes-count-re-in-string holes-empty-hole-regexp exp)))
+ (insert exp)
+ (holes-replace-string-by-holes-backward-move-point c holes-empty-hole-regexp)
+ (if (> c 1) (goto-char pos)
+ (goto-char pos)
+ (holes-set-point-next-hole-destroy) ; if only one hole, go to it.
+ )
+ (if (> c 1) (message "Hit M-ret to jump to active hole. C-h holes-doc to see holes doc.")
+ )
+ )
+ )
+
+(defvar holes-mode nil
+ "Is equal to t if holes mode is on, nil otherwise.")
(make-variable-buffer-local 'holes-mode)
(set-default 'holes-mode nil)
@@ -977,12 +986,12 @@ If arg is positive, then turn holes mode on. If arg is negative, then
turn it off."
(interactive)
(setq holes-mode (if (null arg) (not holes-mode)
- (> (prefix-numeric-value arg) 0)))
+ (> (prefix-numeric-value arg) 0)))
)
(or (assq 'holes-mode minor-mode-alist)
- (setq minor-mode-alist
- (cons '(holes-mode " Holes") minor-mode-alist)))
+ (setq minor-mode-alist
+ (cons '(holes-mode " Holes") minor-mode-alist)))
(provide 'holes)
@@ -991,6 +1000,10 @@ turn it off."
;;; Local Variables:
-;;; tab-width: 2
-;;; End:
+;; End:
+
+;; holes.el ends here
+
+(provide 'holes)
+
;;; holes.el ends here