Permalink
Browse files

Differentiate lib keymap and occurrence keymap

  • Loading branch information...
1 parent 78ac0ea commit 6f80f881342088c09941006966eca8985be8bd96 @victorhge committed Aug 24, 2012
Showing with 41 additions and 58 deletions.
  1. +16 −30 iedit-lib.el
  2. +7 −6 iedit-rect.el
  3. +18 −22 iedit.el
View
@@ -3,7 +3,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2012-08-13 11:19:08 Victor Ren>
+;; Time-stamp: <2012-08-24 09:38:53 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous rectangle refactoring
;; Version: 0.97
@@ -28,7 +28,7 @@
;;; Commentary:
-;; This package is APIs library that allow you to write your own minor mode.
+;; This package is iedit APIs library that allow you to write your own minor mode.
;;; todo:
;; - Update comments for APIs
@@ -70,7 +70,8 @@
"The occurrences slot contains a list of overlays used to
indicate the position of each occurrence. In addition, the
occurrence overlay is used to provide a different face
-configurable via `iedit-occurrence-face'.")
+configurable via `iedit-occurrence-face'. The list is sorted by
+the position of overlays.")
(defvar iedit-case-sensitive-local iedit-case-sensitive-default
"This is buffer local variable.
@@ -112,9 +113,6 @@ insertion against a zero-width occurrence.")
buffering, which means the modification to the current occurrence
is not applied to other occurrences when it is true.")
-;; (defvar iedit-occurrence-keymap 'iedit-occurrence-keymap
-;; "The current keymap, `iedit-occurrence-keymap'")
-
(defvar iedit-occurrence-context-lines 1
"The number of lines before or after the occurrence.")
@@ -127,7 +125,6 @@ is not applied to other occurrences when it is true.")
(make-variable-buffer-local 'iedit-skip-modification-once)
(make-variable-buffer-local 'iedit-aborting)
(make-variable-buffer-local 'iedit-buffering)
-;; (make-variable-buffer-local 'iedit-occurrence-keymap)
(make-variable-buffer-local 'iedit-occurrence-context-lines)
(defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
@@ -203,9 +200,8 @@ This is like `describe-bindings', but displays only Iedit keys."
map)
"Keymap used while Iedit mode is enabled.")
-(defvar iedit-occurrence-keymap
+(defvar iedit-occurrence-keymap-default
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-lib-keymap)
(define-key map (kbd "M-U") 'iedit-upcase-occurrences)
(define-key map (kbd "M-L") 'iedit-downcase-occurrences)
(define-key map (kbd "M-R") 'iedit-replace-occurrences)
@@ -218,10 +214,10 @@ This is like `describe-bindings', but displays only Iedit keys."
(define-key map (kbd "M->") 'iedit-last-occurrence)
(define-key map (kbd "C-?") 'iedit-help-for-occurrences)
map)
- "Keymap used within overlays in Iedit mode.")
+ "Default keymap used within overlays.")
(defun iedit-help-for-occurrences ()
- "Display `iedit-occurrence-keymap'"
+ "Display `iedit-occurrence-keymap-default'"
(interactive)
(message (concat (substitute-command-keys "\\[iedit-upcase-occurrences]") "/"
(substitute-command-keys "\\[iedit-downcase-occurrences]") ":up/downcase "
@@ -235,18 +231,20 @@ This is like `describe-bindings', but displays only Iedit keys."
(substitute-command-keys "\\[iedit-last-occurrence]") ":first/last "
)))
-(defun iedit-make-occurrences-overlays (occurrence-exp beg end)
+(defun iedit-make-occurrences-overlays (occurrence-exp beg end &optional keymap)
"Create occurrence overlays for `occurrence-exp' in a region.
Return the number of occurrences."
(setq iedit-aborting nil)
(setq iedit-occurrences-overlays nil)
+ (unless keymap
+ (setq keymap iedit-occurrence-keymap-default))
;; Find and record each occurrence's markers and add the overlay to the occurrences
(let ((counter 0)
(case-fold-search (not iedit-case-sensitive-local)))
(save-excursion
(goto-char beg)
(while (re-search-forward occurrence-exp end t)
- (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0))
+ (push (iedit-make-occurrence-overlay (match-beginning 0) (match-end 0) keymap)
iedit-occurrences-overlays)
(setq counter (1+ counter)))
(message "%d matches for \"%s\"" counter (iedit-printable occurrence-exp))
@@ -264,49 +262,37 @@ there are."
(error "No region"))
(if (null iedit-occurrences-overlays)
(push
- (iedit-make-occurrence-overlay beg end)
+ (iedit-make-occurrence-overlay beg end iedit-occurrence-keymap-default)
iedit-occurrences-overlays)
(or (= (- end beg) (iedit-occurrence-string-length))
(error "Wrong region."))
(if (or (iedit-find-overlay-at-point beg 'iedit-occurrence-overlay-name)
(iedit-find-overlay-at-point end 'iedit-occurrence-overlay-name))
(error "Conflict region."))
- (push (iedit-make-occurrence-overlay beg end)
+ (push (iedit-make-occurrence-overlay beg end iedit-occurrence-keymap-default)
iedit-occurrences-overlays)
(sort iedit-occurrences-overlays
(lambda (left right)
(< (overlay-start left) (overlay-start right)))))) ;; todo test this function
(defun iedit-cleanup ()
"Clean up occurrence overlay, invisible overlay and local variables."
- ;; (when iedit-buffering
- ;; (iedit-stop-buffering))
- ;; (setq iedit-last-occurrence-local (iedit-current-occurrence-string))
- ;; (setq iedit-last-occurrence-global iedit-last-occurrence-local)
- ;; (setq iedit-last-initial-string-global iedit-initial-string-local)
- ;; (setq iedit-case-sensitive-global iedit-case-sensitive-local)
(remove-overlays nil nil iedit-occurrence-overlay-name t)
(iedit-show-all)
(setq iedit-occurrences-overlays nil)
(setq iedit-aborting nil)
(setq iedit-before-modification-string "")
- (setq iedit-before-modification-undo-list nil)
- ;; (setq iedit-mode nil)
- ;; (force-mode-line-update)
- ;; (remove-hook 'kbd-macro-termination-hook 'iedit-done t)
- ;; (remove-hook 'change-major-mode-hook 'iedit-done t)
- ;; (run-hooks 'iedit-mode-end-hook)
- )
+ (setq iedit-before-modification-undo-list nil))
-(defun iedit-make-occurrence-overlay (begin end)
+(defun iedit-make-occurrence-overlay (begin end keymap)
"Create an overlay for an occurrence in Iedit mode.
Add the properties for the overlay: a face used to display a
occurrence's default value, and modification hooks to update
occurrences if the user starts typing."
(let ((occurrence (make-overlay begin end (current-buffer) nil t)))
(overlay-put occurrence iedit-occurrence-overlay-name t)
(overlay-put occurrence 'face iedit-occurrence-face)
- (overlay-put occurrence 'keymap iedit-occurrence-keymap)
+ (overlay-put occurrence 'keymap keymap)
(overlay-put occurrence 'insert-in-front-hooks '(iedit-occurrence-update))
(overlay-put occurrence 'insert-behind-hooks '(iedit-occurrence-update))
(overlay-put occurrence 'modification-hooks '(iedit-occurrence-update))
View
@@ -2,7 +2,7 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2012-08-10 16:20:22 Victor Ren>
+;; Time-stamp: <2012-08-23 15:30:08 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
;; Keywords: occurrence region simultaneous rectangle refactoring
;; Version: 0.97
@@ -28,8 +28,8 @@
;;; Commentary:
;; This package also provides rectangle support with *visible rectangle*
-;; highlighting, which is similar with cua mode rectangle support, but still
-;; quite different.
+;; highlighting, which is similar with cua mode rectangle support. But it's
+;; lighter weight and uses iedit mechanisms.
;; The code was developed and fully tested on Gnu Emacs 24.0.93, partially
;; tested on Gnu Emacs 22. If you have any compatible problem, please let me
@@ -69,14 +69,14 @@ current mode is iedit-rect. Otherwise it is nil.
;;; Define Iedit rect mode map
(defvar iedit-rect-keymap
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-occurrence-keymap)
+ (set-keymap-parent map iedit-occurrence-keymap-default)
(define-key map (kbd "M-K") 'iedit-kill-rectangle)
map)
"Keymap used within overlays in iedit-RECT mode.")
(or (assq 'iedit-rectangle-mode minor-mode-map-alist)
(setq minor-mode-map-alist
- (cons (cons 'iedit-rectangle-mode iedit-rect-keymap) minor-mode-map-alist)))
+ (cons (cons 'iedit-rectangle-mode iedit-lib-keymap) minor-mode-map-alist)))
;; Avoid to restore Iedit-rect mode when restoring desktop
@@ -115,7 +115,8 @@ current mode is iedit-rect. Otherwise it is nil.
(point))
(progn
(move-to-column end-col t)
- (point)))
+ (point))
+ iedit-rect-keymap)
iedit-occurrences-overlays)
(forward-line 1))
until (> (point) end))
View
@@ -2,9 +2,9 @@
;; Copyright (C) 2010, 2011, 2012 Victor Ren
-;; Time-stamp: <2012-08-10 11:13:42 Victor Ren>
+;; Time-stamp: <2012-08-24 09:40:07 Victor Ren>
;; Author: Victor Ren <victorhge@gmail.com>
-;; Keywords: occurrence region simultaneous rectangle refactoring
+;; Keywords: occurrence region simultaneous refactoring
;; Version: 0.97
;; X-URL: http://www.emacswiki.org/emacs/Iedit
;; Compatibility: GNU Emacs: 22.x, 23.x, 24.x
@@ -34,19 +34,15 @@
;; Normal scenario of iedit-mode is like:
;;
;; - Highlight certain contents - by press C-;
-;; All occurrences of a symbol, string or a rectangle in the buffer or a
-;; region may be highlighted corresponding to current mark, point and prefix
-;; argument. Refer to the document of `iedit-mode' for details.
+;; All occurrences of a symbol, string in the buffer or a region may be
+;; highlighted corresponding to current mark, point and prefix argument.
+;; Refer to the document of `iedit-mode' for details.
;;
;; - Edit one of the occurrences
;; The change is applied to other occurrences simultaneously.
;;
;; - Finish - by pressing C-; again
;;
-;; This package also provides rectangle support with *visible rectangle*
-;; highlighting, which is similar with cua mode rectangle support, but still
-;; quite different.
-
;; You can also use Iedit mode as a quick way to temporarily show only the
;; buffer lines that match the current text being edited. This gives you the
;; effect of a temporary `keep-lines' or `occur'. To get this effect, hit C-'
@@ -83,15 +79,8 @@
;;; Code:
(eval-when-compile (require 'cl))
-(require 'rect) ;; kill rectangle
(require 'iedit-lib)
-(defgroup iedit nil
- "Edit multiple regions in the same way simultaneously."
- :prefix "iedit-"
- :group 'replace
- :group 'convenience)
-
(defcustom iedit-current-symbol-default t
"If no-nil, use current symbol by default for the occurrence."
:type 'boolean
@@ -138,6 +127,7 @@ Iedit mode is turned off last time.")
(make-variable-buffer-local 'iedit-mode)
(make-variable-buffer-local 'iedit-only-complete-symbol-local)
(make-variable-buffer-local 'iedit-last-occurrence-local)
+(make-variable-buffer-local 'iedit-initial-string-local)
(or (assq 'iedit-mode minor-mode-alist)
(nconc minor-mode-alist
@@ -162,14 +152,20 @@ Iedit mode is turned off last time.")
;;; Define iedit help map.
(eval-when-compile (require 'help-macro))
-(defvar iedit-mode-keymap
+(defvar iedit-mode-occurrence-keymap
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map iedit-occurrence-keymap)
+ (set-keymap-parent map iedit-occurrence-keymap-default)
(define-key map (kbd "M-H") 'iedit-restrict-function)
(define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
map)
"Keymap used within overlays in Iedit mode.")
+(defvar iedit-mode-keymap
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map iedit-lib-keymap)
+ (define-key map (kbd "C-'") 'iedit-toggle-unmatched-lines-visible)
+ map)
+ "Keymap used while Iedit mode is enabled.")
;;; Define Iedit mode map
(or (assq 'iedit-mode minor-mode-map-alist)
@@ -220,8 +216,8 @@ as occurrence. If region active, Iedit mode is limited within
the current region.
If Iedit mode is on and region is active, Iedit mode is
-restricted in the region, e.g. the occurrences outside of the region
-is excluded.
+restricted in the region, e.g. the occurrences outside of the
+region is excluded.
If Iedit mode is on and region is active, with an universal
prefix argument, Iedit mode is restricted outside of the region,
@@ -298,7 +294,7 @@ Commands:
(propertize
(concat " Iedit:"
(number-to-string
- (iedit-make-occurrences-overlays occurrence-exp beg end)))
+ (iedit-make-occurrences-overlays occurrence-exp beg end iedit-mode-occurrence-keymap)))
'face
'font-lock-warning-face))
(force-mode-line-update))
@@ -415,7 +411,7 @@ Todo: how about region"
;;; iedit.el ends here
;; LocalWords: iedit el MERCHANTABILITY kbd isearch todo ert Lindberg Tassilo
-;; LocalWords: eval rect defgroup defcustom boolean defvar assq alist nconc
+;; LocalWords: eval defgroup defcustom boolean defvar assq alist nconc
;; LocalWords: substring cadr keymap defconst purecopy bkm defun princ prev
;; LocalWords: iso lefttab backtab upcase downcase concat setq autoload arg
;; LocalWords: refactoring propertize cond goto nreverse progn rotatef eq elp

0 comments on commit 6f80f88

Please sign in to comment.