GithubHelp home page GithubHelp logo

emacsmirror / mode-line-idle Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 41 KB

Evaluate mode line content when idle

Home Page: https://codeberg.org/ideasman42/emacs-mode-line-idle

License: GNU General Public License v3.0

Emacs Lisp 100.00%

mode-line-idle's Introduction

Mode Line Idle

Simple delayed text evaluation for the mode-line.

This package provides a convenient way to defer text evaluation in a way that can be easily integrated into existing mode-line's without requiring a minor mode or configuration.

Available via melpa.

Motivation

To be able to add useful information into the mode-line without slowing down Emacs performance.

While delaying updates is not so difficult, having multiple timers can become awkward when mixed in with the mode-lines configuration.

Instead of avoiding expensive information in the mode-line, it can be calculated when idle.

Usage

To use mode-line-idle you will need to set mode-line-format using eval (examples below).

The function signature is:

(mode-line-idle delay content default-text &rest keywords)

delay:The number of seconds to delay evaluation once Emacs is idle.
content:The text to evaluate which can be a tree that gets converted into a string, this takes on a similar for to mode-line-format (more on this below).
default-text:The text to show before the value has been computed.

Optional Keyword Arguments

:interrupt (boolean)

When non-nil, evaluating the string will be interrupted on key input.

This is intended for long running operations, to prevent them locking Emacs if the user begins typing while the operation is running.

Interruption uses the same behavior as quit, see with-no-input documentation for details.

:literal (boolean)
When non-nil, replace % with %% to prevent mode-line-format from interpreting the character.

Examples

Simple example showing a delayed evaluated block in the mode line.

(defvar my-date '(:eval (current-time-string)))
(setq-default mode-line-format
  (list "Example " '(:eval (mode-line-idle 1.0 my-date "?"))))

The block to evaluate can be included inline as well.

(setq-default mode-line-format
  (list "Example " '(:eval (mode-line-idle 1.0 '(:eval (current-time-string)) "?"))))

As with mode-line-format, propertize is supported.

(defvar my-date '(:propertize (:eval (current-time-string)) face warning))
(setq-default mode-line-format
  (list "Example " '(:eval (mode-line-idle 1.0 my-date "?"))))

Two timers, with different faces.

(defvar my-date '(:eval (current-time-string)))
(defvar my-word '(:eval (count-words (point-min) (point-max))))
(setq-default mode-line-format
  (list "Example " '(:eval (list
                             "Date: "
                             (mode-line-idle 1.0 my-date "...")
                             " Word Count: "
                             (mode-line-idle 3.0 my-word "?" :interrupt t)))))

Utility Functions

(mode-line-idle-force-update &optional delay-in-seconds)

Calculate pending mode-line-idle items immediately.

When delay-in-seconds nil or omitted - update everything. Otherwise skip items with an idle time over this value.

Installation

This package can be installed from melpa.

(use-package mode-line-idle
  :commands (mode-line-idle))

mode-line-idle's People

Contributors

ideasman42 avatar meain avatar

Watchers

 avatar  avatar  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.