Skip to content

Commit

Permalink
with-buffer binds *standard-output*; with-tag uses it
Browse files Browse the repository at this point in the history
  • Loading branch information
stacksmith committed Jun 11, 2017
1 parent d1c2b82 commit d5aa39f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
31 changes: 13 additions & 18 deletions demo.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,16 @@
(gtk-widget-show-all window)))))

(defun populate (buffer tHead tBody tLink tBoldLink)
(with-tag buffer tHead
(format buffer " In the news ~&"))
(with-tag buffer tBody
(format buffer "• United States President Donald Trump (pictured) announces that the U.S. will ")
(with-tag buffer tBoldLink
(format buffer "withdraw from the Paris Agreement"))
(format buffer " on ")
(with-tag buffer tLink
(format buffer "climate change mitigation"))
(format buffer ".~&")

(format buffer "")
(with-tag buffer tBoldLink
(format buffer "A suspected robbery and arson"))
(format buffer " at the ")
(with-tag buffer tLink
(format buffer "Resorts World Manila"))
(format buffer " complex in the Philippines kills at least 34 people and injures 54 others.~&")))
(with-buffer buffer
(with-tag tHead (format t " In the news ~&"))
(with-tag tBody
(format t "• United States President Donald Trump (pictured) announces that the U.S. will ")
(with-tag tBoldLink (format t "withdraw from the Paris Agreement"))
(format t" on ")
(with-tag tLink (format t "climate change mitigation"))
(format t ".~&")
(format t "")
(with-tag tBoldLink (format t "A suspected robbery and arson"))
(format t " at the ")
(with-tag tLink (format t "Resorts World Manila"))
(format t " complex in the Philippines kills at least 34 people and injures 54 others.~&"))))
29 changes: 18 additions & 11 deletions gtk-assets/tb.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,28 @@
t)


(defmacro with-tag (tb tag &rest body)
`(let ((start (gtb-cursor-position ,tb)))
(progn ,@body)
(tb-apply-tag ,tb ,tag start (gtb-cursor-position ,tb))))

(defmacro without-tag (tb tag &rest body)
`(let ((start (gtb-cursor-position ,tb)))
(progn ,@body)
(tb-remove-tag ,tb ,tag start (gtb-cursor-position ,tb))))


(defun tb-cursor-backwards(tb &key count )
(with-slots (iter0) tb
(tb-cursor-iter tb)
(when (if count
(gti-backward-cursor-positions iter0 count)
(gti-backward-cursor-position iter0))
(gtb-place-cursor tb iter0))))

(defmacro with-buffer (tb &rest body)
`(let ((*standard-output* ,tb))
,@body))


(defmacro with-tag (tag &rest body)
`(let ((start (gtb-cursor-position *standard-output*)))
(progn ,@body)
(tb-apply-tag *standard-output* ,tag start
(gtb-cursor-position *standard-output*))))

(defmacro without-tag (tag &rest body)
`(let ((start (gtb-cursor-position *standard-output*)))
(progn ,@body)
(tb-remove-tag *standard-output* ,tag start (gtb-cursor-position *standard-output*))))


0 comments on commit d5aa39f

Please sign in to comment.