Skip to content

Commit

Permalink
remove obsoleted functions
Browse files Browse the repository at this point in the history
fix doc follow the new implementation
  • Loading branch information
mhayashi1120 committed Mar 29, 2012
1 parent f277b18 commit ff30da1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 172 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ The following keybindings are defined:


* `C-c C-e`: Apply the changes to file buffers. * `C-c C-e`: Apply the changes to file buffers.
* `C-c C-u`: All changes are unmarked and ignored. * `C-c C-u`: All changes are unmarked and ignored.
* `C-c C-d`: Delete current line (including newline). This is immediately reflected in the file's buffer. * `C-c C-d`: Delete current line (including newline).
* `C-c C-r`: Remove the changes in the region (these changes are not applied to the files. Of course, the remaining changes can still be applied to the files.) * `C-c C-r`: Remove the changes in the region (these changes are not applied to the files. Of course, the remaining changes can still be applied to the files.)
* `C-c C-p`: Toggle read-only area. * `C-c C-p`: Toggle read-only area.
* `C-c C-k`: Discard all changes and exit. * `C-c C-k`: Discard all changes and exit.
Expand Down
200 changes: 29 additions & 171 deletions wgrep.el
Expand Up @@ -42,7 +42,6 @@
;; C-c C-e : Apply the changes to file buffers. ;; C-c C-e : Apply the changes to file buffers.
;; C-c C-u : All changes are unmarked and ignored. ;; C-c C-u : All changes are unmarked and ignored.
;; C-c C-d : Delete current line (including newline). ;; C-c C-d : Delete current line (including newline).
;; This is immediately reflected in the file's buffer.
;; C-c C-r : Remove the changes in the region (these changes are not ;; C-c C-r : Remove the changes in the region (these changes are not
;; applied to the files. Of course, the remaining ;; applied to the files. Of course, the remaining
;; changes can still be applied to the files.) ;; changes can still be applied to the files.)
Expand Down Expand Up @@ -172,24 +171,23 @@ a file."


(defvar wgrep-mode-map nil) (defvar wgrep-mode-map nil)
(unless wgrep-mode-map (unless wgrep-mode-map
(setq wgrep-mode-map (let ((map (make-sparse-keymap)))
(let ((map (make-sparse-keymap)))

(define-key map "\C-c\C-c" 'wgrep-finish-edit)
(define-key map "\C-c\C-c" 'wgrep-finish-edit) (define-key map "\C-c\C-d" 'wgrep-mark-deletion)
(define-key map "\C-c\C-d" 'wgrep-flush-current-line) (define-key map "\C-c\C-e" 'wgrep-finish-edit)
(define-key map "\C-c\C-e" 'wgrep-finish-edit) (define-key map "\C-c\C-p" 'wgrep-toggle-readonly-area)
(define-key map "\C-c\C-p" 'wgrep-toggle-readonly-area) (define-key map "\C-c\C-r" 'wgrep-remove-change)
(define-key map "\C-c\C-r" 'wgrep-remove-change) (define-key map "\C-x\C-s" 'wgrep-finish-edit)
(define-key map "\C-x\C-s" 'wgrep-finish-edit) (define-key map "\C-c\C-u" 'wgrep-remove-all-change)
(define-key map "\C-c\C-u" 'wgrep-remove-all-change) (define-key map "\C-c\C-[" 'wgrep-remove-all-change)
(define-key map "\C-c\C-[" 'wgrep-remove-all-change) (define-key map "\C-c\C-k" 'wgrep-abort-changes)
(define-key map "\C-c\C-k" 'wgrep-abort-changes) (define-key map "\C-x\C-q" 'wgrep-exit)
(define-key map "\C-x\C-q" 'wgrep-exit) (define-key map "\C-m" 'ignore)
(define-key map "\C-m" 'ignore) (define-key map "\C-j" 'ignore)
(define-key map "\C-j" 'ignore) (define-key map "\C-o" 'ignore)
(define-key map "\C-o" 'ignore)

(setq wgrep-mode-map map)))
map)))


;;;###autoload ;;;###autoload
(defun wgrep-setup () (defun wgrep-setup ()
Expand Down Expand Up @@ -526,70 +524,23 @@ or \\[wgrep-abort-changes] to abort changes.")))
(t (t
(message "%d buffers have been saved." count))))) (message "%d buffers have been saved." count)))))


(defun wgrep-mark-flagged-deletion () (defun wgrep-mark-deletion ()
"TODO" "TODO"
(interactive) (interactive)
(save-excursion (save-excursion
(let ((ov (wgrep-editing-overlay))) (let ((ov (wgrep-editing-overlay)))
(unless ov (unless ov
(error "Not a grep result")) (error "Not a grep result"))
(overlay-put ov 'wgrep-edit-text nil) (condition-case nil
(let ((wgrep-inhibit-modification-hook t) (progn
(begin (overlay-get ov 'wgrep-contents-begin)) (overlay-put ov 'wgrep-edit-text nil)
(end (overlay-end ov))) (let ((wgrep-inhibit-modification-hook t)
(delete-region begin end) (begin (overlay-get ov 'wgrep-contents-begin))
(wgrep-register-edit-overlay ov))))) (end (overlay-end ov)))

(delete-region begin end)
(defun wgrep-flush-current-line () (wgrep-register-edit-overlay ov)))
"Flush current line and file buffer. Undo is disabled for this command. (error
This command immediately changes the file buffer, although the buffer (delete-overlay ov))))))
is not saved.
"
(interactive)
(save-excursion
(let ((inhibit-read-only t))
(forward-line 0)
(unless (looking-at wgrep-line-file-regexp)
(error "Not a grep result"))
(let* ((header (match-string-no-properties 0))
(filename (match-string-no-properties 1))
(line (string-to-number (match-string 3)))
(ov (wgrep-get-flush-overlay))
(old (wgrep-get-old-text header)))
(let ((inhibit-quit t)
(wgrep-inhibit-modification-hook t))
(when (wgrep-flush-apply-to-buffer filename ov line old)
(delete-overlay ov)
;; disable undo temporarily and change *grep* buffer.
(let ((buffer-undo-list t))
(wgrep-delete-whole-line)
(wgrep-after-delete-line filename line))
;; correct evacuated buffer
(with-current-buffer wgrep-each-other-buffer
(let ((inhibit-read-only t))
(wgrep-after-delete-line filename line)))))))))

(defun wgrep-after-delete-line (filename delete-line)
(save-excursion
(wgrep-goto-first-found)
(let ((regexp (format "^%s\\(?::\\)\\([0-9]+\\)\\(?::\\)"
(regexp-quote filename))))
(while (not (eobp))
(when (looking-at regexp)
(let ((line (string-to-number (match-string 1)))
(read-only (get-text-property (point) 'read-only)))
(cond
((= line delete-line)
;; for cloned buffer (flush same line number)
(wgrep-delete-whole-line)
(forward-line -1))
((> line delete-line)
;; down line number
(let ((line-head (format "%s:%d:" filename (1- line))))
(wgrep-set-readonly-property
0 (length line-head) read-only line-head)
(replace-match line-head nil nil nil 0))))))
(forward-line 1)))))


(defun wgrep-prepare-context () (defun wgrep-prepare-context ()
(wgrep-goto-first-found) (wgrep-goto-first-found)
Expand All @@ -610,8 +561,7 @@ is not saved.
(forward-line 1))) (forward-line 1)))


(defun wgrep-delete-whole-line () (defun wgrep-delete-whole-line ()
(wgrep-delete-region (delete-region (line-beginning-position) (line-beginning-position 2)))
(line-beginning-position) (line-beginning-position 2)))


(defun wgrep-goto-first-found () (defun wgrep-goto-first-found ()
(goto-char (point-min)) (goto-char (point-min))
Expand Down Expand Up @@ -639,10 +589,6 @@ is not saved.
(forward-line diff) (forward-line diff)
(setq next (+ diff next)))))) (setq next (+ diff next))))))


(defun wgrep-delete-region (min max)
(remove-text-properties min max '(read-only) (current-buffer))
(delete-region min max))

(defun wgrep-process-exited-p () (defun wgrep-process-exited-p ()
(let ((proc (get-buffer-process (current-buffer)))) (let ((proc (get-buffer-process (current-buffer))))
(or (null proc) (or (null proc)
Expand Down Expand Up @@ -758,35 +704,6 @@ is not saved.
(when (re-search-forward (concat "^" (regexp-quote header)) nil t) (when (re-search-forward (concat "^" (regexp-quote header)) nil t)
(buffer-substring-no-properties (point) (line-end-position)))))) (buffer-substring-no-properties (point) (line-end-position))))))


(defun wgrep-flush-pop-deleting-line ()
(save-window-excursion
(set-window-buffer (selected-window) (current-buffer))
(wgrep-put-color-file
(line-beginning-position) (line-end-position))
(sit-for 0.3)
(wgrep-delete-whole-line)
(sit-for 0.3)))

(defun wgrep-flush-apply-to-buffer (filename ov line old)
(let* ((file (expand-file-name filename default-directory))
(buffer (wgrep-get-file-buffer file)))
(condition-case err
(with-current-buffer buffer
(save-restriction
(widen)
(wgrep-check-buffer)
(wgrep-display-physical-data)
(let ((inhibit-read-only wgrep-change-readonly-file))
(wgrep-goto-line line)
(wgrep-flush-pop-deleting-line)))
t)
(wgrep-error
(wgrep-put-reject-face ov (cdr err))
nil)
(error
(wgrep-put-reject-face ov (prin1-to-string err))
nil))))

;; return alist like following ;; return alist like following
;; key ::= buffer ;; key ::= buffer
;; value ::= linum old-text new-text result-overlay edit-overlay ;; value ::= linum old-text new-text result-overlay edit-overlay
Expand Down Expand Up @@ -926,65 +843,6 @@ is not saved.
(t (t
(message "Undo %d buffers." count))))) (message "Undo %d buffers." count)))))


(defun wgrep-map (function)
(save-excursion
(let (start end)
(wgrep-goto-first-found)
(setq start (point))
(wgrep-goto-end-of-found)
(setq end (point))
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(while (not (eobp))
(when (looking-at wgrep-line-file-regexp)
(let* ((file (match-string-no-properties 1))
(buffer (wgrep-get-file-buffer file))
markers diff)
(with-current-buffer buffer
(setq markers (wgrep-map-line-markers))
(save-excursion
(save-match-data
(funcall function)))
(setq diff (wgrep-map-line-diff markers)))
(wgrep-map-after-call file diff)
(with-current-buffer wgrep-each-other-buffer
(wgrep-map-after-call file diff))))
(forward-line 1))))))

;;TODO not tested yet.
(defun wgrep-map-after-call (file diff)
(let ((inhibit-read-only t)
(file-regexp (regexp-quote file))
after-change-functions)
(save-excursion
(dolist (pair diff)
(let ((old (car pair))
(new (cdr pair)))
(goto-char (point-min))
(when (re-search-forward (format "^%s:\\(%d\\):" file-regexp old) nil t)
(replace-match (number-to-string new) nil nil nil 1)))))))

(defun wgrep-map-line-markers ()
(let (markers)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(setq markers (cons (point-marker) markers))
(forward-line 1)))
(nreverse markers)))

;;TODO deleted line.
(defun wgrep-map-line-diff (markers)
(let ((num 1)
(ret '()))
(dolist (marker markers)
(let ((new (line-number-at-pos (marker-position marker))))
(when (/= new num)
(setq ret (cons (cons num new) ret))))
(setq num (1+ num)))
(nreverse ret)))

;;; ;;;
;;; activate/deactivate marmalade install or github install. ;;; activate/deactivate marmalade install or github install.
;;; ;;;
Expand Down

0 comments on commit ff30da1

Please sign in to comment.