Skip to content

Commit

Permalink
Add `twittering-assoc-string' for portability.
Browse files Browse the repository at this point in the history
* twittering-mode.el: Add `twittering-assoc-string' for
portability. In Emacs 21, the function `assoc-string' is not
defined. In such case, the reimplemented version is
used. Othewise, `twittering-assoc-string' is an alias of
`assoc-string'.
(twittering-assoc-string): new function for portability.
(twittering-get-server-info): replace `assoc-string' with
`twittering-assoc-string'.
  • Loading branch information
cvmat committed Mar 24, 2013
1 parent e71e292 commit d9c2e5e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
(twittering-json-read): use the new advice for decoding surrogate
pairs in strings returned by `json-read'.

* twittering-mode.el: Add `twittering-assoc-string' for
portability. In Emacs 21, the function `assoc-string' is not
defined. In such case, the reimplemented version is
used. Othewise, `twittering-assoc-string' is an alias of
`assoc-string'.
(twittering-assoc-string): new function for portability.
(twittering-get-server-info): replace `assoc-string' with
`twittering-assoc-string'.

2013-03-05 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el: Bind a local variable correctly.
Expand Down
42 changes: 41 additions & 1 deletion twittering-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,44 @@ as a list of a string on Emacs21."
added
(butlast added (- len maxelt)))))))

(if (fboundp 'assoc-string)
(defalias 'twittering-assoc-string 'assoc-string)
(defun twittering-assoc-string (key list &optional case-fold)
"Like `assoc' but specifically for strings (and symbols).
This returns the first element of LIST whose car matches the string or
symbol KEY, or nil if no match exists. When performing the
comparison, symbols are first converted to strings, and unibyte
strings to multibyte. If the optional arg CASE-FOLD is non-nil, case
is ignored.

Unlike `assoc', KEY can also match an entry in LIST consisting of a
single string, rather than a cons cell whose car is a string.

This is reimplemented version of `assoc-string' which is not
defined in Emacs21."
(let* ((key (if (stringp key)
key
(symbol-name key)))
(regexp (concat "\\`" key "\\'"))
(rest list)
(result nil)
(case-fold-search case-fold))
(while (not (null rest))
(let* ((current (car rest))
(current-key
(if (listp current)
(car current)
current))
(current-key
(if (stringp current-key)
current-key
(symbol-name current-key))))
(if (string-match key current-key)
(setq result current
rest nil)
(setq rest (cdr rest)))))
result)))

;;;;
;;;; Debug mode
;;;;
Expand Down Expand Up @@ -5123,7 +5161,9 @@ TIME must be an Emacs internal representation as a return value of
(numeral-field '(ratelimit-remaining ratelimit-limit))
(unix-epoch-time-field '(ratelimit-reset))
(field-name (cdr (assq field table)))
(field-value (cdr (assoc field-name twittering-server-info-alist))))
(field-value
(cdr (twittering-assoc-string
field-name twittering-server-info-alist t))))
(when (and field-name field-value)
(cond
((memq field numeral-field)
Expand Down

0 comments on commit d9c2e5e

Please sign in to comment.