Skip to content

Commit

Permalink
Restore window parameters after automatic redisplaying.
Browse files Browse the repository at this point in the history
* twittering-mode.el: Restore window parameters after automatic
redisplaying.
(twittering-current-window-config): new function.
(twittering-restore-window-config-after-modification): new function.
(twittering-redisplay-status-on-each-buffer): restore window
parameters after redisplaying.
  • Loading branch information
cvmat committed Jun 2, 2010
1 parent f3d1734 commit f96cdb6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Expand Up @@ -9,6 +9,13 @@
(twittering-oauth-get-token-alist-curl): likewise.
(twittering-verify-credentials): likewise.

* twittering-mode.el: Restore window parameters after automatic
redisplaying.
(twittering-current-window-config): new function.
(twittering-restore-window-config-after-modification): new function.
(twittering-redisplay-status-on-each-buffer): restore window
parameters after redisplaying.

2010-05-27 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-toggle-activate-buffer): restart
Expand Down
47 changes: 44 additions & 3 deletions twittering-mode.el
Expand Up @@ -1683,6 +1683,28 @@ image are displayed."
(remove-text-properties 0 (length str) '(need-to-be-updated nil) str))
str))

(defun twittering-current-window-config (window-list)
"Return window parameters of WINDOW-LIST."
(mapcar (lambda (win)
(let ((start (window-start win))
(point (window-point win)))
`(,win ,start ,point)))
window-list))

(defun twittering-restore-window-config-after-modification (config beg end)
"Restore window parameters changed by modification on given region.
CONFIG is window parameters made by `twittering-current-window-config'.
BEG and END mean a region that had been modified."
(mapc (lambda (entry)
(let ((win (elt entry 0))
(start (elt entry 1))
(point (elt entry 2)))
(when (and (< beg start) (< start end))
(set-window-start win start))
(when (and (< beg point) (< point end))
(set-window-point win point))))
config))

;;;
;;; Utility functions for portability
;;;
Expand Down Expand Up @@ -4477,7 +4499,10 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(twittering-get-buffer-list)))

(defun twittering-redisplay-status-on-each-buffer (buffer)
(let ((deactivate-mark deactivate-mark))
(let ((deactivate-mark deactivate-mark)
(window-list (get-buffer-window-list buffer nil t))
(marker (with-current-buffer buffer (point-marker)))
(result nil))
(with-current-buffer buffer
(save-excursion
(twittering-for-each-property-region
Expand All @@ -4486,11 +4511,27 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(let* ((func (car value))
(args (cdr value))
(updated-str (apply func beg end args))
(config (twittering-current-window-config window-list))
(buffer-read-only nil))
;; If the region to be modified includes the current position,
;; the point moves to the beginning of the region.
(when (and (< beg marker) (< marker end))
;; This is required because the point moves to the center if
;; the point becomes outside of the window by the effect of
;; `set-window-start'.
(setq result beg))
(delete-region beg end)
(goto-char beg)
(insert updated-str)))
buffer)))))
(insert-before-markers updated-str)
(twittering-restore-window-config-after-modification
config beg end)))
buffer))
(set-marker marker nil)
(when (and result (eq (window-buffer) buffer))
(let ((win (selected-window)))
(when (< result (window-start win))
(set-window-start win result))
(set-window-point win result))))))

;;;
;;; display functions
Expand Down

0 comments on commit f96cdb6

Please sign in to comment.