preview-tab: VS Code's preview tab for Emacs, now on MELPA

Browsing a project in Emacs leaves a trail of buffers behind. Every file you glanced at in Dired or Treemacs, every definition you jumped to, every grep hit you opened stays in the buffer list forever, and C-x b slowly turns into an archive of things you looked at once. VS Code handles this with the preview tab : a file you open by browsing goes into a single italic tab, the next one replaces it, and it only becomes a real tab once you edit it. I wanted that in Emacs, so I wrote preview-tab : (preview-tab-mode 1) What happens once it's on Opening a file from Dired, Treemacs, Magit, xref, compile/grep results, flymake or consult-ripgrep puts it in one temporary buffer, marked in the mode line (italic path plus an eye icon if you have nerd-icons, otherwise PREVIEW ). Opening the next one kills the previous preview. Editing it, or running preview-tab-keep , turns it into an ordinary buffer. A preview that's modified, visible in another window or running a process is never killed. It quietly becomes an ordinary buffer. A buffer that was already open is never demoted to a preview. What it deliberately doesn't do find-file isn't a preview source by default: typing a file name is a deliberate act, and VS Code doesn't preview from Quick Open either. For a quick peek there's preview-tab-find-file . If you'd rather everything previewed, (setopt preview-tab-include-named-files t) takes in find-file , magit-find-file and org-roam-node-find . Since so much of Emacs opens files through find-file , that also covers project-find-file and recentf . I run with it on myself. Plays well with doom-modeline and centaur-tabs: their faces get italicised out of the box. tab-line-mode : the preview's tab stays italic even when it isn't selected, like VS Code (needs Emacs 28+). Doom Emacs: +lookup/definition , +lookup/references , +default/search-project and friends are in the default list. Anything else: it's advice around the commands in preview-tab-commands , so you can add your own jump commands. One limit is that only files visited synchronously, while the command runs, are picked up. No dependencies, Emacs 27.1+, tested in CI on 27.1 through snapshot. Install (use-package preview-tab :ensure t :config (preview-tab-mode 1)) Doom: ;; packages.el (package! preview-tab) ;; config.el (use-package! preview-tab :config (preview-tab-mode 1)) GitHub: github.com/ismd/preview-tab.el MELPA: melpa.org I'd really like to hear which commands you use to browse code that aren't in the default list yet (dirvish? neotree? eglot/lsp-mode jumps?), and whether the "what counts as browsing" rules match how you work. Bug reports and PRs welcome. Disclosure: I wrote this with Claude's help (it's in the package header); design, review and testing are mine.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论