Skip to content

Commit

Permalink
'save-excursion' that was useless due to 'set-buffer' is fixed.
Browse files Browse the repository at this point in the history
(twittering-http-get-list-index-sentinel): `save-excursion' had no
effect because of the following `set-buffer'. This is fixed so that
`save-excursion' saves the state of `temp-buffer'.
(twittering-get-response-header): Likewise.
(twittering-get-response-body): Likewise.
(twittering-tinyurl-get): Likewise.
  • Loading branch information
cvmat committed Jan 8, 2010
1 parent 3c998bf commit ffe4f78
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
@@ -1,3 +1,13 @@
2010-01-09 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-http-get-list-index-sentinel):
`save-excursion' had no effect because of the following
`set-buffer'. This is fixed so that `save-excursion' saves the
state of `temp-buffer'.
(twittering-get-response-header): Likewise.
(twittering-get-response-body): Likewise.
(twittering-tinyurl-get): Likewise.

2010-01-08 Yuto Hayamizu <y.hayamizu@gmail.com>

* twittering-mode.el (twittering-percent-encode): bug fix:
Expand Down
65 changes: 32 additions & 33 deletions twittering-mode.el
Expand Up @@ -1255,16 +1255,16 @@ Available keywords:
(case-string
status
(("200 OK")
(save-excursion
(set-buffer temp-buffer)
(goto-char (point-min))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(while (re-search-forward
"<slug>\\([-a-zA-Z0-9_]+\\)</slug>" nil t)
(push (match-string 1) indexes)))
(if indexes
(setq twittering-list-index-retrieved indexes)
(setq twittering-list-index-retrieved ""))))
(with-current-buffer temp-buffer
(save-excursion
(goto-char (point-min))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(while (re-search-forward
"<slug>\\([-a-zA-Z0-9_]+\\)</slug>" nil t)
(push (match-string 1) indexes)))
(if indexes
(setq twittering-list-index-retrieved indexes)
(setq twittering-list-index-retrieved "")))))
(t
(setq twittering-list-index-retrieved status)))))))
(when (and (not twittering-debug-mode) (buffer-live-p temp-buffer))
Expand Down Expand Up @@ -1314,33 +1314,33 @@ PARAMETERS is alist of URI parameters.

;; FIXME:
;; curl prints HTTP proxy response header, so strip it
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(when (search-forward-regexp
"HTTP/1\\.[01] 200 Connection established\r\n\r\n" nil t)
(delete-region (point-min) (point)))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(buffer-substring (point-min) (match-end 0))
(error "Failure: invalid HTTP response"))))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(when (search-forward-regexp
"HTTP/1\\.[01] 200 Connection established\r\n\r\n" nil t)
(delete-region (point-min) (point)))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(buffer-substring (point-min) (match-end 0))
(error "Failure: invalid HTTP response")))))

(defun twittering-get-response-body (buffer)
"Exract HTTP response body from HTTP response, parse it as XML, and return a
XML tree as list. Return nil when parse failed.
`buffer' may be a buffer or the name of an existing buffer. "
(if (stringp buffer)
(setq buffer (get-buffer buffer)))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(let ((start (match-end 0)))
(condition-case get-error ;; to guard when `xml-parse-region' failed.
(xml-parse-region start (point-max))
(error (message "Failure: %s" get-error)
nil)))
(error "Failure: invalid HTTP response"))
))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(if (search-forward-regexp "\r?\n\r?\n" nil t)
(let ((start (match-end 0)))
(condition-case get-error ;; to guard when `xml-parse-region' failed.
(xml-parse-region start (point-max))
(error (message "Failure: %s" get-error)
nil)))
(error "Failure: invalid HTTP response"))
)))

(defun twittering-cache-status-datum (status-datum &optional data-var)
"Cache status datum into data-var(default twittering-timeline-data)
Expand Down Expand Up @@ -2016,9 +2016,8 @@ following symbols;
(symbol-name (car x)))
twittering-tinyurl-services-map ", "))))
(if longurl
(save-excursion
(let ((buffer (url-retrieve-synchronously (concat api longurl))))
(set-buffer buffer)
(let ((buffer (url-retrieve-synchronously (concat api longurl))))
(with-current-buffer buffer
(goto-char (point-min))
(if (search-forward-regexp "\n\r?\n\\([^\n\r]*\\)" nil t)
(prog1
Expand Down

0 comments on commit ffe4f78

Please sign in to comment.