Utility functions for buffer manipulation.
- b-append
(buffer string-or-buffer)
- b-binary?
(buffer)
- b-blank?
(buffer)
- b-coding-system
(buffer)
- b-duplicate
(buffer target-buffer &key start end)
- b-erase
(buffer)
- b-insert
(buffer &rest string-or-buffer)
- b-prepend
(buffer string-or-buffer)
- b-string
(buffer &key start end)
- b-string-with-property
(buffer &key start end)
Insert string-or-buffer
to bottom of the buffer
.
(let ((x (get-buffer-create "buf-1"))
(y "yyy"))
(with-current-buffer x
(erase-buffer)
(insert "XXX"))
(b-append x y)
(b-string x)) ; => "XXXyyy"
(let ((f (find-file-noselect "~/f.png")))
(b-binary? f)) ; => t
(let ((f (find-file-noselect "~/a.txt")))
(b-binary? f)) ; => nil
(with-temp-buffer
(b-blank? (current-buffer))) ; => t
(with-temp-buffer
(insert "yey!")
(b-blank? (current-buffer))) ; => nil
(let ((f (find-file-noselect "~/a.txt")))
(b-coding-system f)) ; => utf-8-unix
(let ((f (find-file-noselect "~/f.png")))
(b-coding-system f)) ; => no-conversion
(with-temp-buffer
(let ((new-buffer (get-buffer-create "buf-2"))
(orig (current-buffer)))
(insert "0123456789")
(b-duplicate orig new-buffer)
(b-string new-buffer) ;=> "0123456789"
(b-erase new-buffer)
(b-duplicate orig new-buffer)
(b-string new-buffer :start 6) ;=> "56789"
(b-erase new-buffer)
(b-duplicate orig new-buffer)
(b-string new-buffer :end 6) ;=> "01234"
(b-erase new-buffer)
(b-duplicate orig new-buffer)
(b-string new-buffer :start 4 :end 8) ;=> "3456"
))
(let ((buf (get-buffer-create "buf-3")))
(with-current-buffer buf
(insert "ababababa"))
(b-string buf) ; => "ababababa"
(b-erase buf)
(b-string buf) ;=> ""
)
(with-temp-buffer
(let ((buf (get-buffer-create "buf-4"))
(tmp (current-buffer)))
;; The following idiom is abbreviated to `b-insert'
(with-current-buffer buf
(insert "12345"))
(b-string buf) ; => "12345"
(b-insert buf "aaaaa")
(b-string buf) ;=> "12345aaaaa"
(b-insert buf "67890" "bbbbb")
(b-string buf) ;=> "12345aaaaa67890bbbbb"
(b-insert tmp "zzzzz")
(b-insert buf " | " tmp)
(b-string buf) ;=> "12345aaaaa67890bbbbb | zzzzz"
))
(let ((x (get-buffer-create "buf-1"))
(y "yyy"))
(with-current-buffer x
(erase-buffer)
(insert "XXX"))
(b-prepend x y)
(b-string x)) ; => "yyyXXX"
(let ((buf (get-buffer-create "buf-4")))
(b-erase buf)
(b-string buf) ;=>
(b-insert buf "nurupo")
(b-string buf) ; => "nurupo"
(b-string buf :end 3) ; => "nu"
(b-string buf :start 3) ; => "rupo"
(b-string buf :start 3 :end 5) ; => "ru"
)
(let ((buf (get-buffer-create "buf-5")))
(b-erase buf)
(b-insert buf (propertize "Red" 'face 'bold 'foreground "red"))
(b-string buf) ; => "Red"
(b-string-with-properties buf) ; => #("Red" 0 3 (foreground "red" face bold))
)