Skip to content

Commit

Permalink
`%FILL' accepts an argument, which specifies prefix of filled region.
Browse files Browse the repository at this point in the history
* twittering-mode.el: Add an optional argument for the format
specifier `FILL'. The argument specifies the prefix for the filled
region.
(twittering-status-format): use 2 white spaces as fill-prefix in
default.
(twittering-fill-string): use an additional argument `prefix' as
`fill-prefix' for `fill-region-as-paragraph' if the argument is
non-nil.
(twittering-update-filled-string): transfer the local prefix for
`twittering-fill-string'.
(twittering-generate-formater-for-first-spec): recognize an
optional argument for the format specifier `FILL'.
  • Loading branch information
cvmat committed Jun 2, 2010
1 parent bcfd84c commit 3ef9ed3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Expand Up @@ -41,6 +41,19 @@
(twittering-generate-format-status-function): use new
implementation.

* twittering-mode.el: Add an optional argument for the format
specifier `FILL'. The argument specifies the prefix for the filled
region.
(twittering-status-format): use 2 white spaces as fill-prefix in
default.
(twittering-fill-string): use an additional argument `prefix' as
`fill-prefix' for `fill-region-as-paragraph' if the argument is
non-nil.
(twittering-update-filled-string): transfer the local prefix for
`twittering-fill-string'.
(twittering-generate-formater-for-first-spec): recognize an
optional argument for the format specifier `FILL'.

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

* twittering-mode.el (twittering-toggle-activate-buffer): restart
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Expand Up @@ -39,14 +39,14 @@ existing way.
* Added some format specifiers of tweets.
* Support for recursive format specifiers such as
"%FILL{%FACE[bold]{%C{%m/%d}}: %T}".
* Support for user-defined prefix on filling by "%FILL[prefix]{...}".
* Displaying image files without temporary files.
* Support multiple buffers, where their name is derived from timeline spec.
* Multiple initial timelines by setting a list of timeline spec strings to
the variable `twittering-initial-timeline-spec-string'.
* Toggle automatic retrieval of the timeline by pressing 'a'.
* Improved compatibility with global-font-lock mode.
* Unread statuses notifier on mode-line (experimental).
* Fixed fill-column for the format specifier "%FILL{...}".
* Switching timeline buffers by pressing 'f' or 'b'.
* Graphical indicators for SSL and ACTIVE/INACTIVE state on mode-line.
* Asynchronous retrieval of icon images.
Expand Down
34 changes: 18 additions & 16 deletions twittering-mode.el
Expand Up @@ -221,7 +221,7 @@ Do not modify this variable directly. Use `twittering-activate-buffer',
"*Non-nil means tweets are aligned in reverse order of `http://twitter.com/'.")
(defvar twittering-display-remaining nil
"*If non-nil, display remaining of rate limit on the mode line.")
(defvar twittering-status-format "%i %s, %@:\n%FILL{ %T // from %f%L%r%R}\n "
(defvar twittering-status-format "%i %s, %@:\n%FILL[ ]{%T // from %f%L%r%R}\n "
"Format string for rendering statuses.
Ex. \"%i %s, %@:\\n%FILL{ %T // from %f%L%r%R}\n \"

Expand All @@ -245,8 +245,8 @@ Items:
%t - text filled as one paragraph
%' - truncated
%FACE[face-name]{...} - strings decorated with the specified face.
%FILL{...} - strings filled as a paragraph.
You can use any other specifiers in braces.
%FILL[prefix]{...} - strings filled as a paragraph. The prefix is optional.
You can use any other specifiers in braces.
%f - source
%# - id
")
Expand Down Expand Up @@ -1577,7 +1577,7 @@ image are displayed."
(defun twittering-status-id= (id1 id2)
(equal id1 id2))

(defun twittering-fill-string (str &optional adjustment)
(defun twittering-fill-string (str &optional adjustment prefix)
(when (and (not (boundp 'kinsoku-limit))
enable-kinsoku)
;; `kinsoku-limit' is defined on loading "international/kinsoku.el".
Expand All @@ -1591,9 +1591,6 @@ image are displayed."
(load "international/kinsoku"))
(let* ((kinsoku-limit 1)
(adjustment (+ (or adjustment 0)
(if (and (boundp 'fill-prefix) (stringp fill-prefix))
(string-width fill-prefix)
0)
(if enable-kinsoku
kinsoku-limit
0)))
Expand All @@ -1608,8 +1605,10 @@ image are displayed."
(temporary-fill-column (- (or twittering-fill-column (1- min-width))
adjustment)))
(with-temp-buffer
(let ((fill-column temporary-fill-column))
(insert str)
(let ((fill-column temporary-fill-column)
(fill-prefix (or prefix fill-prefix))
(adaptive-fill-regexp ""))
(insert (concat prefix str))
(fill-region-as-paragraph (point-min) (point-max))
(buffer-substring (point-min) (point-max))))))

Expand Down Expand Up @@ -1660,9 +1659,9 @@ image are displayed."
time-string))
time-string))

(defun twittering-update-filled-string (beg end formater status prefix)
(defun twittering-update-filled-string (beg end formater status prefix local-prefix)
(let* ((str (twittering-fill-string (funcall formater status prefix)
(length prefix)))
(length prefix) local-prefix))
(next (next-single-property-change 0 'need-to-be-updated str))
(properties
(and beg
Expand All @@ -1679,7 +1678,7 @@ image are displayed."
(and next (< next (length str))))
(put-text-property 0 (length str) 'need-to-be-updated
`(twittering-update-filled-string
,formater ,status ,prefix)
,formater ,status ,prefix ,local-prefix)
str)
;; Remove the property required no longer.
(remove-text-properties 0 (length str) '(need-to-be-updated nil) str))
Expand Down Expand Up @@ -4938,16 +4937,19 @@ following symbols;
(rest (cdr pair)))
`((propertize (concat ,@braced-body) 'face ',face-sym)
. ,rest)))
((string-match "\\`FILL{" following)
((string-match "\\`FILL\\(\\[\\([^]]*\\)\\]\\)?{" following)
(let* ((str-after-brace (substring following (match-end 0)))
(prefix-str (match-string 2 following))
(pair (twittering-generate-formater-for-current-level
str-after-brace status-sym prefix-sym))
(filled-body (car pair))
(formater `(lambda (,status-sym ,prefix-sym)
(concat ,@filled-body)))
(formater
`(lambda (,status-sym ,prefix-sym)
(let ((,prefix-sym (concat ,prefix-sym ,prefix-str)))
(concat ,@filled-body))))
(rest (cdr pair)))
`((twittering-update-filled-string
nil nil ,formater ,status-sym ,prefix-sym)
nil nil ,formater ,status-sym ,prefix-sym ,prefix-str)
. ,rest)))
((string-match regexp following)
(let ((specifier (match-string 1 following))
Expand Down

0 comments on commit 3ef9ed3

Please sign in to comment.