emacs-buffer
Use when manipulating Emacs buffers - provides elisp patterns for listing, switching, creating, killing, and working with buffer contents
When & Why to Use This Skill
This Claude skill provides a comprehensive suite of Elisp patterns for advanced Emacs buffer manipulation. It enables seamless automation of buffer lifecycle tasks—including listing, switching, creating, and killing buffers—alongside sophisticated content handling and state management. Designed with accessibility in mind, it also includes specific guidelines for E-ink monitor compatibility, making it an essential tool for developers looking to enhance their Emacs workflow through AI-driven Elisp generation and automation.
Use Cases
- Automated Buffer Management: Efficiently list, switch, or clean up multiple buffers during complex development sessions to maintain an organized workspace.
- Programmatic Text Processing: Read, insert, or transform text within specific buffers to automate documentation updates, log analysis, or code refactoring.
- Safe Scripting with Temporary Buffers: Utilize 'with-temp-buffer' patterns to process data in isolation, ensuring no side effects on the user's active workspace.
- Accessibility-First UI Development: Generate Elisp code that adheres to E-ink display constraints, using font weights and styles instead of colors for visual differentiation.
- State and Property Tracking: Monitor buffer modification states and manage buffer-local variables to build context-aware Emacs extensions.
| name | emacs-buffer |
|---|---|
| description | Use when manipulating Emacs buffers - provides elisp patterns for listing, switching, creating, killing, and working with buffer contents |
Emacs Buffer Skill
Display Guidelines
E-ink Monitor Compatibility: User uses an e-ink monitor that only supports black, white, and grey.
- NEVER use colors (
:foreground "red",:foreground "cyan", etc.) - Use
:weight bold,:weight light,:slant italic,:underline tfor differentiation - Standard Emacs faces (font-lock-*-face) are acceptable as they adapt to themes
Buffer Basics
Get current buffer
(current-buffer) ; returns buffer object
(buffer-name) ; returns buffer name string
(buffer-file-name) ; returns file path or nil
Switch to buffer
(switch-to-buffer "buffer-name")
(set-buffer "buffer-name") ; doesn't change window display
(pop-to-buffer "buffer-name") ; shows in new window
Create buffer
(get-buffer-create "*my-buffer*")
(with-current-buffer (get-buffer-create "*my-buffer*")
;; work in buffer
)
Kill buffer
(kill-buffer "buffer-name")
(kill-buffer (current-buffer))
Buffer Contents
Read buffer text
(buffer-string) ; entire buffer
(buffer-substring start end) ; region
(buffer-substring-no-properties start end) ; without text properties
Insert text
(insert "text")
(insert-buffer-substring other-buffer start end)
Erase buffer
(erase-buffer)
(delete-region start end)
Buffer Properties
Check buffer state
(buffer-modified-p) ; unsaved changes?
(buffer-live-p buf) ; buffer exists?
(get-buffer "name") ; returns buffer or nil
Set buffer properties
(set-buffer-modified-p nil) ; mark as saved
(rename-buffer "new-name")
Buffer Lists
List all buffers
(buffer-list) ; all buffers
(mapcar #'buffer-name (buffer-list)) ; just names
Filter buffers
;; Get file-visiting buffers
(seq-filter #'buffer-file-name (buffer-list))
;; Get buffers matching pattern
(seq-filter (lambda (b)
(string-match-p "\\*claude" (buffer-name b)))
(buffer-list))
Working with Buffer Positions
Point operations
(point) ; current position
(point-min) ; buffer start
(point-max) ; buffer end
(goto-char pos) ; move to position
Save and restore position
(save-excursion
;; point and buffer restored after body
(goto-char (point-min))
(search-forward "text"))
Temporary Buffers
with-temp-buffer
(with-temp-buffer
(insert "temporary content")
(buffer-string)) ; returns content, buffer killed after
Generate new buffer
(generate-new-buffer "*unique-name*")
Buffer-Local Variables
Set buffer-local
(setq-local my-var "value")
(make-local-variable 'my-var)
Check if buffer-local
(local-variable-p 'my-var)
(buffer-local-value 'my-var some-buffer)
Common Patterns
Process buffer safely
(when-let ((buf (get-buffer "*my-buffer*")))
(with-current-buffer buf
;; work with buffer
))
Create output buffer
(let ((buf (get-buffer-create "*output*")))
(with-current-buffer buf
(erase-buffer)
(insert "Output:\n")
(insert result))
(display-buffer buf))
Find buffer by mode
(seq-find (lambda (b)
(with-current-buffer b
(derived-mode-p 'org-mode)))
(buffer-list))