1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00
emacs/lisp/ruler-mode.el

761 lines
29 KiB
EmacsLisp
Raw Normal View History

;;; ruler-mode.el --- display a ruler in the header line -*- lexical-binding: t -*-
2001-10-09 12:10:17 +00:00
2024-01-02 01:47:10 +00:00
;; Copyright (C) 2001-2024 Free Software Foundation, Inc.
2001-10-09 12:10:17 +00:00
;; Author: David Ponce <david@dponce.com>
;; Created: 24 Mar 2001
;; Old-Version: 1.6
;; Keywords: convenience
2001-10-09 12:10:17 +00:00
;; This file is part of GNU Emacs.
2008-05-06 16:29:23 +00:00
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
2001-10-09 12:10:17 +00:00
2008-05-06 16:29:23 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
2001-10-09 12:10:17 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2001-10-09 12:10:17 +00:00
;;; Commentary:
;; This library provides a minor mode to display a ruler in the header
;; line.
2001-10-09 12:10:17 +00:00
;;
;; You can use the mouse to change the `fill-column' `comment-column',
;; `goal-column', `window-margins' and `tab-stop-list' settings:
2001-10-09 12:10:17 +00:00
;;
;; [header-line (shift down-mouse-1)] set left margin end to the ruler
2001-10-09 12:10:17 +00:00
;; graduation where the mouse pointer is on.
;;
;; [header-line (shift down-mouse-3)] set right margin beginning to
;; the ruler graduation where the mouse pointer is on.
2001-10-09 12:10:17 +00:00
;;
;; [header-line down-mouse-2] Drag the `fill-column', `comment-column'
;; or `goal-column' to a ruler graduation.
2001-10-09 12:10:17 +00:00
;;
;; [header-line (control down-mouse-1)] add a tab stop to the ruler
;; graduation where the mouse pointer is on.
;;
;; [header-line (control down-mouse-3)] remove the tab stop at the
;; ruler graduation where the mouse pointer is on.
;;
;; [header-line (control down-mouse-2)] or M-x
;; `ruler-mode-toggle-show-tab-stops' toggle showing and visually
;; editing `tab-stop-list' setting. The `ruler-mode-show-tab-stops'
;; option controls if the ruler shows tab stops by default.
;;
;; In the ruler the character `ruler-mode-current-column-char' shows
;; the `current-column' location, `ruler-mode-fill-column-char' shows
;; the `fill-column' location, `ruler-mode-comment-column-char' shows
;; the `comment-column' location, `ruler-mode-goal-column-char' shows
;; the `goal-column' and `ruler-mode-tab-stop-char' shows tab stop
;; locations. Graduations in `window-margins' and `window-fringes'
;; areas are shown with a different foreground color.
2001-10-09 12:10:17 +00:00
;;
;; It is also possible to customize the following characters:
;;
;; - `ruler-mode-basic-graduation-char' character used for basic
;; graduations ('.' by default).
;; - `ruler-mode-inter-graduation-char' character used for
;; intermediate graduations ('!' by default).
;;
;; The following faces are customizable:
;;
;; - `ruler-mode-default' the ruler default face.
;; - `ruler-mode-fill-column' the face used to highlight the
2001-10-09 12:10:17 +00:00
;; `fill-column' character.
;; - `ruler-mode-comment-column' the face used to highlight the
;; `comment-column' character.
;; - `ruler-mode-goal-column' the face used to highlight the
;; `goal-column' character.
;; - `ruler-mode-current-column' the face used to highlight the
2001-10-09 12:10:17 +00:00
;; `current-column' character.
;; - `ruler-mode-tab-stop' the face used to highlight tab stop
2001-10-09 12:10:17 +00:00
;; characters.
;; - `ruler-mode-margins' the face used to highlight graduations
;; in the `window-margins' areas.
;; - `ruler-mode-fringes' the face used to highlight graduations
;; in the `window-fringes' areas.
;; - `ruler-mode-column-number' the face used to highlight the
;; numbered graduations.
2001-10-09 12:10:17 +00:00
;;
;; `ruler-mode-default' inherits from the built-in `default' face.
;; All `ruler-mode' faces inherit from `ruler-mode-default'.
2001-10-09 12:10:17 +00:00
;;
;; WARNING: To keep ruler graduations aligned on text columns it is
;; important to use the same font family and size for ruler and text
;; areas.
2004-04-16 12:51:06 +00:00
;;
;; You can override the ruler format by defining an appropriate
;; function as the buffer-local value of `ruler-mode-ruler-function'.
2001-10-09 12:10:17 +00:00
;; Installation
;;
;; To automatically display the ruler in specific major modes use:
;;
;; (add-hook '<major-mode>-hook 'ruler-mode)
2001-10-09 12:10:17 +00:00
;;; Code:
(eval-when-compile
(require 'wid-edit))
2004-04-16 12:51:06 +00:00
(require 'scroll-bar)
(require 'fringe)
2001-10-09 12:10:17 +00:00
(defgroup ruler-mode nil
"Display a ruler in the header line."
:version "22.1"
:group 'convenience)
2001-10-09 12:10:17 +00:00
(defcustom ruler-mode-show-tab-stops nil
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"If non-nil the ruler shows tab stop positions.
2001-10-09 12:10:17 +00:00
Also allowing to visually change `tab-stop-list' setting using
<C-down-mouse-1> and <C-down-mouse-3> on the ruler to respectively add
or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or
<C-down-mouse-2> on the ruler toggles showing/editing of tab stops."
:type 'boolean)
;; IMPORTANT: This function must be defined before the following
;; defcustoms because it is used in their :validate clause.
(defun ruler-mode-character-validate (widget)
"Ensure WIDGET value is a valid character value."
(save-excursion
(let ((value (widget-value widget)))
(unless (characterp value)
2001-10-09 12:10:17 +00:00
(widget-put widget :error
(format "Invalid character value: %S" value))
widget))))
(defcustom ruler-mode-fill-column-char (if (char-displayable-p )
?\¶
2001-10-09 12:10:17 +00:00
?\|)
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used at the `fill-column' location."
2001-10-09 12:10:17 +00:00
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-comment-column-char ?\#
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used at the `comment-column' location."
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-goal-column-char ?G
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used at the `goal-column' location."
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-current-column-char (if (char-displayable-p )
?\¦
2001-10-09 12:10:17 +00:00
?\@)
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used at the `current-column' location."
2001-10-09 12:10:17 +00:00
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-tab-stop-char ?\T
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used at `tab-stop-list' locations."
2001-10-09 12:10:17 +00:00
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-basic-graduation-char ?\.
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used for basic graduations."
2001-10-09 12:10:17 +00:00
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-inter-graduation-char ?\!
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Character used for intermediate graduations."
2001-10-09 12:10:17 +00:00
:type '(choice
(character :tag "Character")
(integer :tag "Integer char value"
:validate ruler-mode-character-validate)))
(defcustom ruler-mode-set-goal-column-ding-flag t
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Non-nil means do `ding' when `goal-column' is set."
:type 'boolean)
(defface ruler-mode-default
2001-10-09 12:10:17 +00:00
'((((type tty))
(:inherit default
:background "grey64"
:foreground "grey50"
))
(t
(:inherit default
:background "grey76"
:foreground "grey64"
:box (:color "grey76"
:line-width 1
:style released-button)
)))
"Default face used by the ruler.")
2001-10-09 12:10:17 +00:00
(defface ruler-mode-pad
'((((type tty))
(:inherit ruler-mode-default
:background "grey50"
))
(t
(:inherit ruler-mode-default
:background "grey64"
)))
"Face used to pad inactive ruler areas.")
(defface ruler-mode-margins
'((t
(:inherit ruler-mode-default
:foreground "white"
)))
"Face used to highlight margin areas.")
(defface ruler-mode-fringes
'((t
(:inherit ruler-mode-default
:foreground "green"
)))
"Face used to highlight fringes areas.")
(defface ruler-mode-column-number
2001-10-09 12:10:17 +00:00
'((t
(:inherit ruler-mode-default
2001-10-09 12:10:17 +00:00
:foreground "black"
)))
"Face used to highlight number graduations.")
2001-10-09 12:10:17 +00:00
(defface ruler-mode-fill-column
2001-10-09 12:10:17 +00:00
'((t
(:inherit ruler-mode-default
2001-10-09 12:10:17 +00:00
:foreground "red"
)))
"Face used to highlight the fill column character.")
2001-10-09 12:10:17 +00:00
(defface ruler-mode-comment-column
'((t
(:inherit ruler-mode-default
:foreground "red"
)))
"Face used to highlight the comment column character.")
(defface ruler-mode-goal-column
'((t
(:inherit ruler-mode-default
:foreground "red"
)))
"Face used to highlight the goal column character.")
(defface ruler-mode-tab-stop
2001-10-09 12:10:17 +00:00
'((t
(:inherit ruler-mode-default
2001-10-09 12:10:17 +00:00
:foreground "steelblue"
)))
"Face used to highlight tab stop characters.")
2001-10-09 12:10:17 +00:00
(defface ruler-mode-current-column
2001-10-09 12:10:17 +00:00
'((t
(:inherit ruler-mode-default
2001-10-09 12:10:17 +00:00
:weight bold
:foreground "yellow"
)))
"Face used to highlight the `current-column' character.")
(defsubst ruler-mode-full-window-width ()
"Return the full width of the selected window."
(let ((edges (window-edges)))
(- (nth 2 edges) (nth 0 edges))))
(defsubst ruler-mode-window-col (event)
"Return a column number relative to the selected window.
EVENT is the mouse event that gives the current column.
If required, account for screen estate taken by `display-line-numbers'."
(let ((n (car (posn-col-row event))))
(when display-line-numbers
Make :align-to account for display-line-numbers These changes also update the various bundled packages to use new feature, and better support customizations of the line-number face. * src/xdisp.c (calc_pixel_width_or_height): Improve commentary. Make :align-to count from the end of the line-number display when the offset or the width form reference that of the text area. (Bug#28855) * src/indent.c (Fline_number_display_width): Implement support for the PIXELWISE argument being 'columns'. Update the doc string. (syms_of_indent): New symbol 'columns'. * lisp/ruler-mode.el (ruler-mode-window-col, ruler-mode-ruler): Call line-number-display-width with last argument 'columns'. * lisp/proced.el (proced-header-line): Call line-number-display-width with 2nd arg 'columns', which also fixes a problem when display-line-numbers is nil. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-line-number-width): Call line-number-display-width with 2nd arg 'columns. (tabulated-list-entry-lnum-width): Remove unneeded defvar. (tabulated-list-print, tabulated-list-print-entry): No need to account for the value of tabulated-list-entry-lnum-width. (tabulated-list--current-lnum-width): New defvar. (tabulated-list-watch-line-number-width): New function. (tabulated-list-mode): Bind tabulated-list--current-lnum-width locally, and set up tabulated-list-watch-line-number-width as pre-redisplay-functions hook. * doc/lispref/display.texi (Size of Displayed Text): Document the 'columns' value of the PIXELWISE argument. (Pixel Specification): Update and improve the documentation of the supported forms.
2017-10-20 09:36:12 +00:00
;; FIXME: ruler-mode relies on N being an integer, so if the
;; 'line-number' face is customized to use a font that is larger
;; or smaller than that of the default face, the alignment might
;; be off by up to half a column, unless the font width is an
;; integral multiple or divisor of the default face's font.
(setq n (- n (round (line-number-display-width 'columns)))))
(- n
(if (eq (posn-area event) 'header-line)
(+ (or (car (window-margins)) 0)
(fringe-columns 'left)
(scroll-bar-columns 'left))
0))))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-mouse-set-left-margin (start-event)
"Set left margin end to the graduation where the mouse pointer is on.
2001-10-09 12:10:17 +00:00
START-EVENT is the mouse click event."
(interactive "e")
(let* ((start (event-start start-event))
(end (event-end start-event))
col w lm rm)
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
(setq col (- (car (posn-col-row start))
2004-04-16 12:51:06 +00:00
(scroll-bar-columns 'left))
w (- (ruler-mode-full-window-width)
2004-04-16 12:51:06 +00:00
(scroll-bar-columns 'left)
(scroll-bar-columns 'right)))
(when (and (>= col 0) (< col w))
(setq lm (window-margins)
rm (or (cdr lm) 0)
lm (or (car lm) 0))
(message "Left margin set to %d (was %d)" col lm)
(set-window-margins nil col rm))))))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-mouse-set-right-margin (start-event)
"Set right margin beginning to the graduation where the mouse pointer is on.
2001-10-09 12:10:17 +00:00
START-EVENT is the mouse click event."
(interactive "e")
(let* ((start (event-start start-event))
(end (event-end start-event))
col w lm rm)
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
(setq col (- (car (posn-col-row start))
2004-04-16 12:51:06 +00:00
(scroll-bar-columns 'left))
w (- (ruler-mode-full-window-width)
2004-04-16 12:51:06 +00:00
(scroll-bar-columns 'left)
(scroll-bar-columns 'right)))
(when (and (>= col 0) (< col w))
(setq lm (window-margins)
rm (or (cdr lm) 0)
lm (or (car lm) 0)
col (- w col 1))
(message "Right margin set to %d (was %d)" col rm)
(set-window-margins nil lm col))))))
(defvar ruler-mode-dragged-symbol nil
"Column symbol dragged in the ruler.
That is `fill-column', `comment-column', `goal-column', or nil when
nothing is dragged.")
(defun ruler-mode-text-scaled-width (width)
"Compute scaled text width according to current font scaling.
Convert a WIDTH of char units into a text-scaled char width units,
for example `window-hscroll'."
(/ (* width (frame-char-width)) (default-font-width)))
(defun ruler-mode-text-scaled-window-hscroll ()
"Text scaled `window-hscroll'."
(ruler-mode-text-scaled-width (window-hscroll)))
(defun ruler-mode-text-scaled-window-width ()
"Text scaled `window-width'."
(ruler-mode-text-scaled-width (window-width)))
(defun ruler-mode-mouse-grab-any-column (start-event)
"Drag a column symbol on the ruler.
Start dragging on mouse down event START-EVENT, and update the column
symbol value with the current value of the ruler graduation while
dragging. See also the variable `ruler-mode-dragged-symbol'."
2001-10-09 12:10:17 +00:00
(interactive "e")
(setq ruler-mode-dragged-symbol nil)
(let* ((start (event-start start-event))
col newc oldc)
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col start)
newc (+ col (ruler-mode-text-scaled-window-hscroll)))
(and
(>= col 0) (< col (ruler-mode-text-scaled-window-width))
(cond
;; Handle the fill column.
((eq newc fill-column)
(setq oldc fill-column
ruler-mode-dragged-symbol 'fill-column)
t) ;; Start dragging
;; Handle the comment column.
((eq newc comment-column)
(setq oldc comment-column
ruler-mode-dragged-symbol 'comment-column)
t) ;; Start dragging
;; Handle the goal column.
;; A. On mouse down on the goal column character on the ruler,
;; update the `goal-column' value while dragging.
;; B. If `goal-column' is nil, set the goal column where the
;; mouse is clicked.
;; C. On mouse click on the goal column character on the
;; ruler, unset the goal column.
((eq newc goal-column) ; A. Drag the goal column.
(setq oldc goal-column
ruler-mode-dragged-symbol 'goal-column)
t) ;; Start dragging
((null goal-column) ; B. Set the goal column.
(setq oldc goal-column
goal-column newc)
;; mouse-2 coming AFTER drag-mouse-2 invokes `ding'. This
;; `ding' flushes the next messages about setting goal
;; column. So here I force fetch the event(mouse-2) and
;; throw away.
Make libraries works with xterm-mouse-mode. Change calls from 'read-event' to 'read-key' in libraries expecting mouse events. Do this only when 'xterm-mouse-mode' is enabled. That way those libraries read decoded mouse events instead of the underlying escape sequence. Add a parameter to 'read-key' that avoids running any of the unbound fallbacks in 'read-key-sequence' so the libraries can read mouse button-down events. For backward compatibility purposes, the above logic is contained in a new internal-only function: 'read--potential-mouse-event'. * doc/lispref/commands.texi (Reading One Event): Document new parameter to 'read-key'. Mention that non-character events on terminals need 'read-key'. * lisp/subr.el (read-key-full-map): Add new keymap used by 'read-key'. (read-key): Add new parameter 'fallbacks-disabled' to prevent running any of the unbound fallbacks normally run by 'read-key-sequence'. (read--potential-mouse-event): Add new function that calls 'read-key' or 'read-event' depending on if 'xterm-mouse-mode' is set. * lisp/foldout.el (foldout-mouse-swallow-events): * lisp/isearch.el (isearch-pre-command-hook): * lisp/mouse-drag.el (mouse-drag-throw, mouse-drag-drag): * lisp/mouse.el (mouse-drag-secondary): * lisp/ruler-mode.el (ruler-mode-mouse-grab-any-column) (ruler-mode-mouse-drag-any-column-iteration): * lisp/strokes.el (strokes-read-stroke, strokes-read-complex-stroke): * lisp/textmodes/artist.el (artist-mouse-draw-continously) (artist-mouse-draw-poly, artist-mouse-draw-2points): * lisp/vc/ediff-wind.el (ediff-get-window-by-clicking): * lisp/wid-edit.el (widget-button--check-and-call-button) (widget-button-click): Call 'read--potential-mouse-event' instead of 'read-event'. * lisp/wid-edit.el (widget-key-sequence-read-event): Call 'read-key' with 'fallbacks-disabled' set instead of 'read-event'. Unlike above changes, this is unconditionally applied so it works for function keys too. Apply 'local-function-key-map' instead of 'function-key-map' as that contains the full terminal translations. * lisp/vc/ediff.el (ediff-windows): Use 'display-mouse-p' to check if a mouse is available. * src/lread.c (Fread_event): Recommend 'read-key' in docstring for 'read-event' for non-character events.
2021-01-02 22:10:17 +00:00
(read--potential-mouse-event)
;; Ding BEFORE `message' is OK.
(when ruler-mode-set-goal-column-ding-flag
(ding))
(message "Goal column set to %d (click on %s again to unset it)"
newc
(propertize (char-to-string ruler-mode-goal-column-char)
'face 'ruler-mode-goal-column))
nil) ;; Don't start dragging.
)
(if (eq 'click (ruler-mode-mouse-drag-any-column-iteration
(posn-window start)))
(when (eq 'goal-column ruler-mode-dragged-symbol)
;; C. Unset the goal column.
(set-goal-column t))
;; At end of dragging, report the updated column symbol.
(message "%s is set to %d (was %d)"
ruler-mode-dragged-symbol
(symbol-value ruler-mode-dragged-symbol)
oldc))))))
(defun ruler-mode-mouse-drag-any-column-iteration (window)
"Update the ruler while dragging the mouse.
WINDOW is the window where occurred the last down-mouse event.
Return the symbol `drag' if the mouse has been dragged, or `click' if
the mouse has been clicked."
(let ((drags 0)
event)
(track-mouse
;; Signal the display engine to freeze the mouse pointer shape.
(setq track-mouse 'dragging)
Make libraries works with xterm-mouse-mode. Change calls from 'read-event' to 'read-key' in libraries expecting mouse events. Do this only when 'xterm-mouse-mode' is enabled. That way those libraries read decoded mouse events instead of the underlying escape sequence. Add a parameter to 'read-key' that avoids running any of the unbound fallbacks in 'read-key-sequence' so the libraries can read mouse button-down events. For backward compatibility purposes, the above logic is contained in a new internal-only function: 'read--potential-mouse-event'. * doc/lispref/commands.texi (Reading One Event): Document new parameter to 'read-key'. Mention that non-character events on terminals need 'read-key'. * lisp/subr.el (read-key-full-map): Add new keymap used by 'read-key'. (read-key): Add new parameter 'fallbacks-disabled' to prevent running any of the unbound fallbacks normally run by 'read-key-sequence'. (read--potential-mouse-event): Add new function that calls 'read-key' or 'read-event' depending on if 'xterm-mouse-mode' is set. * lisp/foldout.el (foldout-mouse-swallow-events): * lisp/isearch.el (isearch-pre-command-hook): * lisp/mouse-drag.el (mouse-drag-throw, mouse-drag-drag): * lisp/mouse.el (mouse-drag-secondary): * lisp/ruler-mode.el (ruler-mode-mouse-grab-any-column) (ruler-mode-mouse-drag-any-column-iteration): * lisp/strokes.el (strokes-read-stroke, strokes-read-complex-stroke): * lisp/textmodes/artist.el (artist-mouse-draw-continously) (artist-mouse-draw-poly, artist-mouse-draw-2points): * lisp/vc/ediff-wind.el (ediff-get-window-by-clicking): * lisp/wid-edit.el (widget-button--check-and-call-button) (widget-button-click): Call 'read--potential-mouse-event' instead of 'read-event'. * lisp/wid-edit.el (widget-key-sequence-read-event): Call 'read-key' with 'fallbacks-disabled' set instead of 'read-event'. Unlike above changes, this is unconditionally applied so it works for function keys too. Apply 'local-function-key-map' instead of 'function-key-map' as that contains the full terminal translations. * lisp/vc/ediff.el (ediff-windows): Use 'display-mouse-p' to check if a mouse is available. * src/lread.c (Fread_event): Recommend 'read-key' in docstring for 'read-event' for non-character events.
2021-01-02 22:10:17 +00:00
(while (mouse-movement-p (setq event (read--potential-mouse-event)))
(setq drags (1+ drags))
(when (eq window (posn-window (event-end event)))
(ruler-mode-mouse-drag-any-column event)
(force-mode-line-update))))
(if (and (zerop drags) (eq 'click (car (event-modifiers event))))
'click
'drag)))
(defun ruler-mode-mouse-drag-any-column (start-event)
"Update the value of the symbol dragged on the ruler.
Called on each mouse motion event START-EVENT."
2001-10-09 12:10:17 +00:00
(let* ((start (event-start start-event))
(end (event-end start-event))
col newc)
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col end)
newc (+ col (ruler-mode-text-scaled-window-hscroll)))
(when (and (>= col 0) (< col (ruler-mode-text-scaled-window-width)))
(set ruler-mode-dragged-symbol newc)))))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-mouse-add-tab-stop (start-event)
"Add a tab stop to the graduation where the mouse pointer is on.
START-EVENT is the mouse click event."
(interactive "e")
(when ruler-mode-show-tab-stops
(let* ((start (event-start start-event))
(end (event-end start-event))
col ts)
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col start)
ts (+ col (ruler-mode-text-scaled-window-hscroll)))
(and (>= col 0) (< col (ruler-mode-text-scaled-window-width))
(not (member ts tab-stop-list))
(progn
(message "Tab stop set to %d" ts)
(when (null tab-stop-list)
(setq tab-stop-list (indent-accumulate-tab-stops (1- ts))))
(setq tab-stop-list (sort (cons ts tab-stop-list) #'<)))))))))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-mouse-del-tab-stop (start-event)
"Delete tab stop at the graduation where the mouse pointer is on.
START-EVENT is the mouse click event."
(interactive "e")
(when ruler-mode-show-tab-stops
(let* ((start (event-start start-event))
(end (event-end start-event))
col ts)
(when (eq start end) ;; mouse click
(save-selected-window
(select-window (posn-window start))
(setq col (ruler-mode-window-col start)
ts (+ col (ruler-mode-text-scaled-window-hscroll)))
(and (>= col 0) (< col (ruler-mode-text-scaled-window-width))
(member ts tab-stop-list)
(progn
(message "Tab stop at %d deleted" ts)
(setq tab-stop-list (delete ts tab-stop-list)))))))))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-toggle-show-tab-stops ()
"Toggle showing of tab stops on the ruler."
(interactive)
(setq ruler-mode-show-tab-stops (not ruler-mode-show-tab-stops))
(force-mode-line-update))
(defvar-keymap ruler-mode-map
:doc "Keymap for `ruler-mode'."
"<header-line> <down-mouse-1>" #'ignore
"<header-line> <down-mouse-3>" #'ignore
"<header-line> <down-mouse-2>" #'ruler-mode-mouse-grab-any-column
"<header-line> S-<down-mouse-1>" #'ruler-mode-mouse-set-left-margin
"<header-line> S-<down-mouse-3>" #'ruler-mode-mouse-set-right-margin
"<header-line> C-<down-mouse-1>" #'ruler-mode-mouse-add-tab-stop
"<header-line> C-<down-mouse-3>" #'ruler-mode-mouse-del-tab-stop
"<header-line> C-<down-mouse-2>" #'ruler-mode-toggle-show-tab-stops
"<header-line> S-<mouse-1>" #'ignore
"<header-line> S-<mouse-3>" #'ignore
"<header-line> C-<mouse-1>" #'ignore
"<header-line> C-<mouse-3>" #'ignore
"<header-line> C-<mouse-2>" #'ignore)
2001-10-09 12:10:17 +00:00
(defvar ruler-mode-header-line-format-old nil
"Hold previous value of `header-line-format'.")
2004-04-16 12:51:06 +00:00
(defvar ruler-mode-ruler-function #'ruler-mode-ruler
2004-04-16 12:51:06 +00:00
"Function to call to return ruler header line format.
This variable is expected to be made buffer-local by modes.")
2001-10-09 12:10:17 +00:00
(defconst ruler-mode-header-line-format
2004-04-16 12:51:06 +00:00
'(:eval (funcall ruler-mode-ruler-function))
"`header-line-format' used in ruler mode.
Call `ruler-mode-ruler-function' to compute the ruler value.")
2001-10-09 12:10:17 +00:00
;;;###autoload
Prefer defvar-local in remaining libraries * lisp/align.el (align-mode-rules-list) (align-mode-exclude-rules-list): * lisp/bookmark.el (bookmark-current-bookmark) (bookmark-annotation-name) (bookmark--annotation-from-bookmark-list): * lisp/calc/calc-embed.el (calc-embedded-all-active) (calc-embedded-some-active): * lisp/comint.el (comint-password-function): * lisp/completion.el (completion-syntax-table): * lisp/dframe.el (dframe-track-mouse-function) (dframe-help-echo-function, dframe-mouse-click-function) (dframe-mouse-position-function, dframe-timer) (dframe-attached-frame, dframe-controlled): * lisp/ehelp.el (electric-help-orig-major-mode): * lisp/eshell/esh-util.el (eshell-path-env): * lisp/expand.el (expand-pos, expand-index, expand-point): * lisp/face-remap.el (text-scale-mode-remapping) (text-scale-mode-lighter, text-scale-mode-amount) (text-scale-remap-header-line, buffer-face-mode-remapping): * lisp/ffap.el (ffap-menu-alist): * lisp/files-x.el (connection-local-variables-alist): * lisp/foldout.el (foldout-fold-list, foldout-mode-line-string): * lisp/follow.el (follow-start-end-invalid): * lisp/forms.el (forms--mode-setup): * lisp/gnus/message.el (message-cross-post-old-target) (message-options): * lisp/help-mode.el (help-xref-stack, help-xref-forward-stack) (help-xref-stack-item, help-xref-stack-forward-item): * lisp/hexl.el (hexl-mode--old-var-vals, hexl-ascii-overlay): * lisp/hilit-chg.el (hilit-chg-string): * lisp/ido.el (ido-eoinput): * lisp/imenu.el (imenu-generic-expression) (imenu-create-index-function, imenu-default-goto-function) (imenu-prev-index-position-function) (imenu-extract-index-name-function, imenu-name-lookup-function) (imenu-syntax-alist, imenu-case-fold-search): * lisp/jka-compr.el (jka-compr-really-do-compress): * lisp/language/ethio-util.el (ethio-prefer-ascii-space): * lisp/leim/quail/hangul.el (hangul-input-method-help-text): * lisp/leim/quail/japanese.el (quail-japanese-package-saved): * lisp/linum.el (linum-overlays, linum-available): * lisp/man.el (Man-original-frame, Man-arguments, Man--sections) (Man--refpages, Man-page-list, Man-current-page) (Man-page-mode-string): * lisp/pcomplete.el (pcomplete-current-completions) (pcomplete-last-completion-length) (pcomplete-last-completion-stub, pcomplete-last-completion-raw) (pcomplete-last-window-config, pcomplete-window-restore-timer): * lisp/reveal.el (reveal-open-spots, reveal-last-tick): * lisp/ruler-mode.el (ruler-mode): * lisp/scroll-lock.el (scroll-lock-preserve-screen-pos-save): * lisp/server.el (server-buffer-clients, server-existing-buffer): * lisp/tab-line.el (tab-line-exclude): * lisp/tar-mode.el (tar-data-buffer, tar-data-swapped): * lisp/thumbs.el (thumbs-current-tmp-filename) (thumbs-current-image-filename, thumbs-extra-images) (thumbs-image-num, thumbs-buffer, thumbs-marked-list): * lisp/tutorial.el (tutorial--point-before-chkeys) (tutorial--point-after-chkeys, tutorial--lang): * lisp/url/url-vars.el (url-current-object) (url-current-mime-headers, url-current-lastloc): * lisp/view.el (view-mode, view-old-buffer-read-only) (view-old-Helper-return-blurb, view-page-size) (view-half-page-size, view-last-regexp, view-return-to-alist) (view-exit-action, view-overlay): * lisp/wid-edit.el (widget-global-map, widget-field-new) (widget-field-list, widget-field-last, widget-field-was): * lisp/woman.el (woman-imenu-done): Prefer defvar-local.
2021-02-02 08:55:40 +00:00
(defvar-local ruler-mode nil
"Non-nil if Ruler mode is enabled.
Use the command `ruler-mode' to change this variable.")
(defun ruler--save-header-line-format ()
"Install the header line format for Ruler mode.
Unless Ruler mode is already enabled, save the old header line
format first."
(when (and (not ruler-mode)
(local-variable-p 'header-line-format)
(not (local-variable-p 'ruler-mode-header-line-format-old)))
Prefer setq-local in most files * lisp/apropos.el (apropos-print): * lisp/buff-menu.el (Buffer-menu-mode): * lisp/calc/calc.el (calc-trail-buffer): * lisp/chistory.el (command-history-mode): * lisp/dabbrev.el: * lisp/dframe.el (dframe-frame-mode): * lisp/doc-view.el (doc-view-presentation-mode): * lisp/ebuff-menu.el (electric-buffer-menu-mode) (electric-buffer-update-highlight): * lisp/edmacro.el (edit-kbd-macro): * lisp/face-remap.el (buffer-face-set, buffer-face-toggle): * lisp/files.el: (find-file-noselect-1, hack-local-variables-confirm) (set-visited-file-name, revert-buffer--default): * lisp/filesets.el (filesets-spawn-external-viewer): * lisp/find-dired.el (find-dired): * lisp/find-lisp.el (find-lisp-find-dired-internal): * lisp/finder.el (finder-mode): * lisp/font-core.el (font-lock-default-function): * lisp/format.el (format-annotate-function): * lisp/help-fns.el (describe-variable): * lisp/help-mode.el (help-mode): * lisp/icomplete.el (icomplete-minibuffer-setup) (icomplete--in-region-setup): * lisp/ido.el (ido-completion-help, ido-tidy): * lisp/international/robin.el (robin-activate): * lisp/leim/quail/hangul.el (hangul-input-method-activate): * lisp/leim/quail/uni-input.el (ucs-input-activate): * lisp/man.el (Man-mode): * lisp/master.el (master-set-slave): * lisp/minibuffer.el (minibuffer-completion-help) (read-file-name-default): * lisp/outline.el (outline-minor-mode): * lisp/pcomplete.el (pcomplete-comint-setup): * lisp/proced.el (proced-mode): * lisp/recentf.el (recentf-edit-list, recentf-open-files-items): * lisp/replace.el (occur-1): * lisp/reveal.el (reveal-mode): * lisp/ruler-mode.el (ruler--save-header-line-format): * lisp/scroll-lock.el (scroll-lock-mode): * lisp/startup.el (normal-top-level, normal-splash-screen): * lisp/strokes.el (strokes-list-strokes): * lisp/thumbs.el (thumbs-insert-image, thumbs-show-thumbs-list): * lisp/tree-widget.el (tree-widget-set-theme): * lisp/window.el (read-buffer-to-switch): * lisp/xwidget.el (xwidget-webkit-begin-edit-textarea): Prefer setq-local.
2020-12-09 08:44:38 +00:00
(setq-local ruler-mode-header-line-format-old
header-line-format))
(setq header-line-format ruler-mode-header-line-format))
2001-10-09 12:10:17 +00:00
;;;###autoload
(define-minor-mode ruler-mode
"Toggle display of ruler in header line (Ruler mode)."
2001-10-09 12:10:17 +00:00
:group 'ruler-mode
:variable (ruler-mode
. (lambda (enable)
(when enable
(ruler--save-header-line-format))
(setq ruler-mode enable)))
2001-10-09 12:10:17 +00:00
(if ruler-mode
(add-hook 'post-command-hook #'force-mode-line-update nil t)
2001-10-09 12:10:17 +00:00
;; When `ruler-mode' is off restore previous header line format if
;; the current one is the ruler header line format.
(when (eq header-line-format ruler-mode-header-line-format)
(kill-local-variable 'header-line-format)
(when (local-variable-p 'ruler-mode-header-line-format-old)
2004-04-16 12:51:06 +00:00
(setq header-line-format ruler-mode-header-line-format-old)
(kill-local-variable 'ruler-mode-header-line-format-old)))
(remove-hook 'post-command-hook #'force-mode-line-update t)))
2002-01-13 10:09:20 +00:00
;; Add ruler-mode to the minor mode menu in the mode line
2001-10-09 12:10:17 +00:00
(define-key mode-line-mode-menu [ruler-mode]
Replace insignificant backquotes Replace most insignificant occurrences of '`' with a straight quote, sharp quote or nothing. This includes backquotes in 'pcase' patterns. * admin/admin.el: * lisp/apropos.el: * lisp/arc-mode.el: * lisp/auth-source.el: * lisp/avoid.el: * lisp/bindings.el: * lisp/bs.el: * lisp/calculator.el: * lisp/calendar/todo-mode.el: * lisp/cedet/semantic.el: * lisp/cedet/semantic/analyze/debug.el: * lisp/cedet/semantic/bovine.el: * lisp/cedet/semantic/dep.el: * lisp/cedet/semantic/grammar.el: * lisp/cedet/semantic/wisent/comp.el: * lisp/cedet/semantic/wisent/grammar.el: * lisp/cedet/srecode/mode.el: * lisp/cus-edit.el: * lisp/doc-view.el: * lisp/elec-pair.el: * lisp/electric.el: * lisp/emacs-lisp/autoload.el: * lisp/emacs-lisp/benchmark.el: * lisp/emacs-lisp/byte-opt.el: * lisp/emacs-lisp/bytecomp.el: * lisp/emacs-lisp/cconv.el: * lisp/emacs-lisp/cl-extra.el: * lisp/emacs-lisp/cl-generic.el: * lisp/emacs-lisp/cl-macs.el: * lisp/emacs-lisp/copyright.el: * lisp/emacs-lisp/debug.el: * lisp/emacs-lisp/eieio-compat.el: * lisp/emacs-lisp/ert.el: * lisp/emacs-lisp/generator.el: * lisp/emacs-lisp/inline.el: * lisp/emacs-lisp/macroexp.el: * lisp/emacs-lisp/map.el: * lisp/emacs-lisp/package-x.el: * lisp/emacs-lisp/package.el: * lisp/emacs-lisp/radix-tree.el: * lisp/emacs-lisp/smie.el: * lisp/epa.el: * lisp/erc/erc-dcc.el: * lisp/erc/erc-track.el: * lisp/erc/erc.el: * lisp/eshell/em-ls.el: * lisp/eshell/esh-cmd.el: * lisp/files.el: * lisp/filesets.el: * lisp/font-lock.el: * lisp/frameset.el: * lisp/gnus/gnus-agent.el: * lisp/gnus/gnus-art.el: * lisp/gnus/gnus-cite.el: * lisp/gnus/gnus-group.el: * lisp/gnus/gnus-msg.el: * lisp/gnus/gnus-salt.el: * lisp/gnus/gnus-srvr.el: * lisp/gnus/gnus-sum.el: * lisp/gnus/gnus-topic.el: * lisp/gnus/gnus-util.el: * lisp/gnus/gnus.el: * lisp/gnus/message.el: * lisp/gnus/mm-util.el: * lisp/gnus/mml.el: * lisp/gnus/nnheader.el: * lisp/gnus/nnimap.el: * lisp/gnus/nnmairix.el: * lisp/gnus/spam.el: * lisp/hexl.el: * lisp/hi-lock.el: * lisp/ibuf-ext.el: * lisp/ibuffer.el: * lisp/ido.el: * lisp/info.el: * lisp/international/mule-cmds.el: * lisp/international/mule-util.el: * lisp/json.el: * lisp/jsonrpc.el: * lisp/language/cyrillic.el: * lisp/language/european.el: * lisp/language/georgian.el: * lisp/language/tibetan.el: * lisp/language/utf-8-lang.el: * lisp/language/vietnamese.el: * lisp/ldefs-boot.el: * lisp/mail/mail-extr.el: * lisp/man.el: * lisp/menu-bar.el: * lisp/mh-e/mh-acros.el: * lisp/mh-e/mh-folder.el: * lisp/mh-e/mh-mime.el: * lisp/mh-e/mh-show.el: * lisp/mh-e/mh-speed.el: * lisp/minibuffer.el: * lisp/mpc.el: * lisp/net/ange-ftp.el: * lisp/net/hmac-def.el: * lisp/net/newst-backend.el: * lisp/net/quickurl.el: * lisp/net/tramp-archive.el: * lisp/net/tramp-compat.el: * lisp/notifications.el: * lisp/obsolete/pgg-parse.el: * lisp/obsolete/vc-arch.el: * lisp/obsolete/xesam.el: * lisp/org/ob-C.el: * lisp/org/ob-core.el: * lisp/org/ob-exp.el: * lisp/org/ob-groovy.el: * lisp/org/ob-haskell.el: * lisp/org/ob-io.el: * lisp/org/ob-lisp.el: * lisp/org/ob-lob.el: * lisp/org/ob-lua.el: * lisp/org/ob-octave.el: * lisp/org/ob-perl.el: * lisp/org/ob-python.el: * lisp/org/ob-ref.el: * lisp/org/ob-ruby.el: * lisp/org/ob-sql.el: * lisp/org/org-agenda.el: * lisp/org/org-capture.el: * lisp/org/org-clock.el: * lisp/org/org-colview.el: * lisp/org/org-duration.el: * lisp/org/org-element.el: * lisp/org/org-entities.el: * lisp/org/org-gnus.el: * lisp/org/org-indent.el: * lisp/org/org-info.el: * lisp/org/org-inlinetask.el: * lisp/org/org-lint.el: * lisp/org/org-list.el: * lisp/org/org-mouse.el: * lisp/org/org-plot.el: * lisp/org/org-src.el: * lisp/org/org-table.el: * lisp/org/org.el: * lisp/org/ox-ascii.el: * lisp/org/ox-html.el: * lisp/org/ox-latex.el: * lisp/org/ox-man.el: * lisp/org/ox-md.el: * lisp/org/ox-org.el: * lisp/org/ox-publish.el: * lisp/org/ox-texinfo.el: * lisp/org/ox.el: * lisp/play/bubbles.el: * lisp/play/gamegrid.el: * lisp/progmodes/autoconf.el: * lisp/progmodes/cc-defs.el: * lisp/progmodes/cc-engine.el: * lisp/progmodes/cc-fonts.el: * lisp/progmodes/cc-langs.el: * lisp/progmodes/cperl-mode.el: * lisp/progmodes/ebrowse.el: * lisp/progmodes/elisp-mode.el: * lisp/progmodes/flymake-cc.el: * lisp/progmodes/flymake.el: * lisp/progmodes/fortran.el: * lisp/progmodes/grep.el: * lisp/progmodes/gud.el: * lisp/progmodes/idlwave.el: * lisp/progmodes/js.el: * lisp/progmodes/m4-mode.el: * lisp/progmodes/make-mode.el: * lisp/progmodes/mixal-mode.el: * lisp/progmodes/modula2.el: * lisp/progmodes/octave.el: * lisp/progmodes/opascal.el: * lisp/progmodes/prolog.el: * lisp/progmodes/ps-mode.el: * lisp/progmodes/python.el: * lisp/progmodes/ruby-mode.el: * lisp/progmodes/sh-script.el: * lisp/progmodes/sql.el: * lisp/progmodes/verilog-mode.el: * lisp/ps-mule.el: * lisp/rtree.el: * lisp/ruler-mode.el: * lisp/ses.el: * lisp/simple.el: * lisp/startup.el: * lisp/subr.el: * lisp/term/ns-win.el: * lisp/textmodes/bibtex.el: * lisp/textmodes/conf-mode.el: * lisp/textmodes/css-mode.el: * lisp/textmodes/refill.el: * lisp/textmodes/sgml-mode.el: * lisp/textmodes/tex-mode.el: * lisp/tutorial.el: * lisp/url/url-dav.el: * lisp/url/url-gw.el: * lisp/url/url-http.el: * lisp/url/url-methods.el: * lisp/url/url-privacy.el: * lisp/vc/cvs-status.el: * lisp/vc/diff-mode.el: * lisp/vc/ediff-init.el: * lisp/vc/ediff-ptch.el: * lisp/vc/log-edit.el: * lisp/vc/log-view.el: * lisp/vc/pcvs-info.el: * lisp/vc/pcvs.el: * lisp/vc/smerge-mode.el: * lisp/vc/vc-git.el: * lisp/vc/vc-hg.el: * lisp/vc/vc-mtn.el: * lisp/vc/vc-rcs.el: * lisp/whitespace.el: * lisp/window.el: * test/lisp/electric-tests.el: * test/lisp/emacs-lisp/cl-lib-tests.el: * test/lisp/emacs-lisp/ert-tests.el: * test/lisp/epg-tests.el: * test/lisp/jsonrpc-tests.el: * test/src/data-tests.el: * test/src/json-tests.el: Replace most insignificant backquotes.
2018-11-05 00:22:15 +00:00
'(menu-item "Ruler" ruler-mode
:button (:toggle . ruler-mode)))
2001-10-09 12:10:17 +00:00
(defconst ruler-mode-ruler-help-echo
"\
S-mouse-1/3: set L/R margin, \
mouse-2: set goal column, \
2001-10-09 12:10:17 +00:00
C-mouse-2: show tabs"
"Help string shown when mouse is over the ruler.
2001-10-09 12:10:17 +00:00
`ruler-mode-show-tab-stops' is nil.")
(defconst ruler-mode-ruler-help-echo-when-goal-column
"\
S-mouse-1/3: set L/R margin, \
C-mouse-2: show tabs"
"Help string shown when mouse is over the ruler.
`goal-column' is set and `ruler-mode-show-tab-stops' is nil.")
(defconst ruler-mode-ruler-help-echo-when-tab-stops
2001-10-09 12:10:17 +00:00
"\
C-mouse1/3: set/unset tab, \
C-mouse-2: hide tabs"
"Help string shown when mouse is over the ruler.
2001-10-09 12:10:17 +00:00
`ruler-mode-show-tab-stops' is non-nil.")
(defconst ruler-mode-fill-column-help-echo
"drag-mouse-2: set fill column"
"Help string shown when mouse is on the fill column character.")
(defconst ruler-mode-comment-column-help-echo
"drag-mouse-2: set comment column"
"Help string shown when mouse is on the comment column character.")
(defconst ruler-mode-goal-column-help-echo
"\
drag-mouse-2: set goal column, \
mouse-2: unset goal column"
"Help string shown when mouse is on the goal column character.")
(defconst ruler-mode-margin-help-echo
"%s margin %S"
"Help string shown when mouse is over a margin area.")
2001-10-09 12:10:17 +00:00
(defconst ruler-mode-fringe-help-echo
"%s fringe %S"
"Help string shown when mouse is over a fringe area.")
2004-04-16 12:51:06 +00:00
(defsubst ruler-mode-space (width &rest props)
"Return a single space string of WIDTH times the normal character width.
Optional argument PROPS specifies other text properties to apply."
(apply #'propertize " " 'display (list 'space :width width) props))
2001-10-09 12:10:17 +00:00
(defun ruler-mode-ruler ()
"Compute and return a header line ruler."
(let* ((w (ruler-mode-text-scaled-window-width))
2004-04-16 12:51:06 +00:00
(m (window-margins))
(f (window-fringes))
Make :align-to account for display-line-numbers These changes also update the various bundled packages to use new feature, and better support customizations of the line-number face. * src/xdisp.c (calc_pixel_width_or_height): Improve commentary. Make :align-to count from the end of the line-number display when the offset or the width form reference that of the text area. (Bug#28855) * src/indent.c (Fline_number_display_width): Implement support for the PIXELWISE argument being 'columns'. Update the doc string. (syms_of_indent): New symbol 'columns'. * lisp/ruler-mode.el (ruler-mode-window-col, ruler-mode-ruler): Call line-number-display-width with last argument 'columns'. * lisp/proced.el (proced-header-line): Call line-number-display-width with 2nd arg 'columns', which also fixes a problem when display-line-numbers is nil. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-line-number-width): Call line-number-display-width with 2nd arg 'columns. (tabulated-list-entry-lnum-width): Remove unneeded defvar. (tabulated-list-print, tabulated-list-print-entry): No need to account for the value of tabulated-list-entry-lnum-width. (tabulated-list--current-lnum-width): New defvar. (tabulated-list-watch-line-number-width): New function. (tabulated-list-mode): Bind tabulated-list--current-lnum-width locally, and set up tabulated-list-watch-line-number-width as pre-redisplay-functions hook. * doc/lispref/display.texi (Size of Displayed Text): Document the 'columns' value of the PIXELWISE argument. (Pixel Specification): Update and improve the documentation of the supported forms.
2017-10-20 09:36:12 +00:00
(i (if display-line-numbers
;; FIXME: ruler-mode relies on I being an integer, so
;; the column numbers might be slightly off if the
;; line-number face is customized.
(round (line-number-display-width 'columns))
0))
(j (ruler-mode-text-scaled-window-hscroll))
2004-04-16 12:51:06 +00:00
;; Setup the scrollbar, fringes, and margins areas.
(lf (ruler-mode-space
'left-fringe
'face 'ruler-mode-fringes
2004-04-16 12:51:06 +00:00
'help-echo (format ruler-mode-fringe-help-echo
"Left" (or (car f) 0))))
(rf (ruler-mode-space
'right-fringe
'face 'ruler-mode-fringes
2004-04-16 12:51:06 +00:00
'help-echo (format ruler-mode-fringe-help-echo
"Right" (or (cadr f) 0))))
(lm (ruler-mode-space
'left-margin
'face 'ruler-mode-margins
2004-04-16 12:51:06 +00:00
'help-echo (format ruler-mode-margin-help-echo
"Left" (or (car m) 0))))
(rm (ruler-mode-space
'right-margin
'face 'ruler-mode-margins
2004-04-16 12:51:06 +00:00
'help-echo (format ruler-mode-margin-help-echo
"Right" (or (cdr m) 0))))
(sb (ruler-mode-space
'scroll-bar
'face 'ruler-mode-pad))
2004-04-16 12:51:06 +00:00
;; Remember the scrollbar vertical type.
(sbvt (car (window-current-scroll-bars)))
;; Create a "clean" ruler.
2004-04-16 12:51:06 +00:00
(ruler
;; Make the part of header-line corresponding to the
;; line-number display be blank, not filled with
;; ruler-mode-basic-graduation-char.
(if (> i 0)
(vconcat (make-vector i ?\s)
(make-vector (- w i)
ruler-mode-basic-graduation-char))
(make-vector w ruler-mode-basic-graduation-char)))
(ruler-wide-props
`( face ruler-mode-default
;; This is redundant with the minor mode map.
;;local-map ruler-mode-map
help-echo ,(cond (ruler-mode-show-tab-stops
ruler-mode-ruler-help-echo-when-tab-stops)
(goal-column
ruler-mode-ruler-help-echo-when-goal-column)
(ruler-mode-ruler-help-echo))))
(props nil)
2004-04-16 12:51:06 +00:00
k c)
;; Setup the active area.
(while (< i w)
;; Graduations.
(cond
;; Show a number graduation.
((= (mod j 10) 0)
(setq c (number-to-string (/ j 10))
m (length c)
k i)
(push `(,i ,(1+ i) face ruler-mode-column-number) props)
2004-04-16 12:51:06 +00:00
(while (and (> m 0) (>= k 0))
(aset ruler k (aref c (setq m (1- m))))
(setq k (1- k))))
;; Show an intermediate graduation.
((= (mod j 5) 0)
(aset ruler i ruler-mode-inter-graduation-char)))
;; Special columns.
(cond
;; Show the `current-column' marker.
((= j (current-column))
(aset ruler i ruler-mode-current-column-char)
(push `(,i ,(1+ i) face ruler-mode-current-column) props))
2004-04-16 12:51:06 +00:00
;; Show the `goal-column' marker.
((and goal-column (= j goal-column))
(aset ruler i ruler-mode-goal-column-char)
(push `(,i ,(1+ i)
help-echo ,ruler-mode-goal-column-help-echo
face ruler-mode-goal-column
mouse-face mode-line-highlight)
props))
2004-04-16 12:51:06 +00:00
;; Show the `comment-column' marker.
((= j comment-column)
(aset ruler i ruler-mode-comment-column-char)
(push `(,i ,(1+ i)
help-echo ,ruler-mode-comment-column-help-echo
face ruler-mode-comment-column
mouse-face mode-line-highlight)
props))
2004-04-16 12:51:06 +00:00
;; Show the `fill-column' marker.
((= j fill-column)
(aset ruler i ruler-mode-fill-column-char)
(push `(,i ,(1+ i)
help-echo ,ruler-mode-fill-column-help-echo
face ruler-mode-fill-column
mouse-face mode-line-highlight)
props))
2004-04-16 12:51:06 +00:00
;; Show the `tab-stop-list' markers.
((and ruler-mode-show-tab-stops (= j (indent-next-tab-stop (1- j))))
2004-04-16 12:51:06 +00:00
(aset ruler i ruler-mode-tab-stop-char)
(push `(,i ,(1+ i) face ruler-mode-tab-stop) props)))
2004-04-16 12:51:06 +00:00
(setq i (1+ i)
j (1+ j)))
(let ((ruler-str (concat ruler))
(len (length ruler)))
(add-text-properties 0 len ruler-wide-props ruler-str)
(dolist (p (nreverse props))
(add-text-properties (nth 0 p) (nth 1 p) (nthcdr 2 p) ruler-str))
;; Return the ruler propertized string. Using list here,
;; instead of concat visually separate the different areas.
(if (nth 2 (window-fringes))
;; fringes outside margins.
(list "" (and (eq 'left sbvt) sb) lf lm
ruler-str rm rf (and (eq 'right sbvt) sb))
;; fringes inside margins.
(list "" (and (eq 'left sbvt) sb) lm lf
ruler-str rf rm (and (eq 'right sbvt) sb))))))
2001-10-09 12:10:17 +00:00
(provide 'ruler-mode)
;;; ruler-mode.el ends here