Coder Social home page Coder Social logo

frame-purpose.el's Introduction

frame-purpose.el

http://melpa.org/packages/frame-purpose-badge.svg

frame-purpose makes it easy to open purpose-specific frames that only show certain buffers, e.g. by buffers’ major mode, their filename or directory, etc, with custom frame/X-window titles, icons, and other frame parameters.

Note that this does not lock buffers to certain frames, and it does not prevent frames from showing any buffer. It works by overriding the buffer-list function so that, within a purpose-specific frame, any code that uses buffer-list (e.g. list-buffers, ibuffer, Helm buffer-related commands) will only show buffers for that frame’s purpose. You could say that, within a purpose-specific frame, you would have to “go out of your way” to show a buffer that’s not related to that frame’s purpose.

Note: You may also find the frame-workflow package useful, which integrates with this one.

Usage

First, enable frame-purpose-mode. This overrides buffer-list with a function that acts appropriately on purpose-specific frames. When the mode is disabled, buffer-list is returned to its original definition, and purpose-specific frames will no longer act specially.

There are some built-in interactive commands:

  • frame-purpose-make-directory-frame: Make a purpose-specific frame for buffers associated with DIRECTORY. DIRECTORY defaults to the current buffer’s directory.
  • frame-purpose-make-mode-frame: Make a purpose-specific frame for buffers in major MODE. MODE defaults to the current buffer’s major mode.
  • frame-purpose-show-sidebar: Show list of purpose-specific buffers on SIDE of this frame. When a buffer in the list is selected, the last-used window switches to that buffer. Makes a new buffer if necessary. SIDE is a symbol, one of left, right, top, or bottom.

For more fine-grained control, or for scripted use, the primary function is frame-purpose-make-frame.

Examples

Make a frame to show only Org-mode buffers, with a custom frame (X window) title and icon:

(frame-purpose-make-frame :modes 'org-mode
                          :title "Org"
                          :icon-type "~/src/emacs/org-mode/logo.png")

Make a frame to show only matrix-client buffers, with a custom frame (X window) title and icon, and showing a list of buffers in a sidebar window on the right side of the frame:

(frame-purpose-make-frame :modes 'matrix-client-mode
                          :title "Matrix"
                          :icon-type (expand-file-name "~/src/emacs/matrix-client-el/logo.png")
                          :sidebar 'right)

Make a frame to show only Web-development-related buffers:

;; `:modes' can be one or a list of items, each of which may be either a major mode symbol, or a
;; string which is matched as a regexp against major mode names.
(frame-purpose-make-frame :modes '("html-" "css-" js-mode)
                          :title "Web development")

Screenshots

images/screenshot.png

Installation

If you installed from MELPA, you’re done!

Manual

Install dash.el, put frame-purpose.el in your load-path, and (require 'frame-purpose) in your init file.

use-package and general

If you use use-package and general (and you should), you could put this in your init file:

(use-package frame-purpose
  :general
  (:prefix "M-SPC"
    "Fd" #'frame-purpose-make-directory-frame
    "Fm" #'frame-purpose-make-mode-frame))

Then you could press M-SPC F d to open a new directory-specific frame, and M-SPC F m to open a new mode-specific frame.

Changelog

1.2-pre

Added

  • Add optional argument :sidebar-update-fn to function frame-purpose-make-frame, allowing the sidebar update function to be overridden.

Fixed

  • Only set cursor as invisible in non-selected windows.
  • Frames without :sidebar-buffers-fn. (#17. Thanks to Manuel Wiesinger for reporting.)

1.1

Added

  • Add optional argument :buffer-sort-fns to function frame-purpose-make-frame, allowing a list of custom buffer sorting functions to override the default.

Changed

  • Use buffer-local-value instead of with-current-buffer. This significantly improves performance, as buffer-local-value benchmarks at about 55x faster than using with-current-buffer to get the value of a variable in a buffer.

Fixed

  • frame-purpose-show-sidebar: Use designated sidebar side.
  • Preserve sidebar window size when frame is resized.
  • Put point at beginning of sidebar buffer.

1.0

First tagged version.

Notes

For one reason or another, using a sidebar with buffers in some major modes may cause problems. For example, elfeed-search-update uses temporary buffers to download and process feeds, and every time it opens or closes a temp buffer, buffer-list is called, which updates the list of buffers in the sidebar, and this seems to significantly slow down the feed updating process. Until a fix or workaround can be found, it’s best to simply avoid using a sidebar with these major modes. So, if frame-purpose-show-sidebar is called from a buffer in one of the major modes in the blacklist (or a major mode matching one of the strings in it), an error will be signaled (it’s not a perfect solution, but it should help).

Suggestions to workaround this issue are welcome.

Prior Art

There are a variety of powerful packages to help users manage buffers, like eyebrowse, perspective, persp-mode, workgroups, workgroups2, and others. I found them a bit confusing and complicated for my needs. I simply wanted to open frames to display certain sets of buffers, e.g. to have one frame for my Matrix/IRC chat-room buffers, one for my personal Org buffers, one for a certain Emacs package’s files, etc. Some people use dedicated Emacs processes to separate tasks, but I prefer to use a single Emacs process. Also, while some of those packages provide handy persistence features, I don’t want that complexity, and I don’t necessarily want buffers or frames automatically opened when I start Emacs (and desktop.el provides that, when I need it).

So when I discovered the buffer-predicate frame parameter, and realized that I could (apparently!) safely override buffer-list with a version that uses frames’ buffer-predicate, this package naturally fell into place as a simple way to make purpose-specific frames.

Development

Contributions are welcome! Please report any problems or suggestions on the issue tracker.

License

GPLv3

frame-purpose.el's People

Contributors

alphapapa avatar akirak avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.