読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

バッファに書き込む内容を得る

Emacs Lisp
;; buftest1バッファを作成してThis is a test buffer.をぶちこむ
(with-current-buffer (generate-new-buffer "buftest1")
  (insert "This is a test buffer.\n")
  (buffer-string)			; => "This is a test buffer.\n"
  (buffer-substring 1 5)		; => "This"
  (buffer-substring 6 8)		; => "is"
  )
;;; substringとはインデックスがずれるので注意
(substring "This is a test buffer.\n" 1 5) ; => "his "
(substring "This is a test buffer.\n" 6 8) ; => "s "
(substring "This is a test buffer.\n" -8)  ; => "buffer.\n"
;; buftest2バッファを作成してinsert-buffer-substringを利用してその
;; バッファにbuftestの内容を書き込む
(with-current-buffer (generate-new-buffer "buftest2")
  (insert-buffer-substring "buftest1")
  (buffer-string)			; => "This is a test buffer.\n"
  (insert-buffer-substring "buftest2" 1 5)
  (buffer-string)			; => "This is a test buffer.\nThis"
  )

buftest1バッファの内容

This is a test buffer.


buftest2バッファの内容

This is a test buffer.
This

P106

Emacs Lispテクニックバイブル

Emacs Lispテクニックバイブル