
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark if-let and when-let obsolete (bug#73853 and elsewhere). Move docstring text around so that if-let* and when-let* descriptions no longer refer to if-let and when-let. * etc/NEWS: Announce the change. * admin/admin.el (reminder-for-release-blocking-bugs): * doc/misc/erc.texi (display-buffer): * lisp/ansi-color.el (ansi-color-apply) (ansi-color--face-vec-face): * lisp/ansi-osc.el (ansi-osc-apply-on-region) (ansi-osc-hyperlink): * lisp/arc-mode.el (archive-goto-file) (archive-next-file-displayer): * lisp/auth-source-pass.el (auth-source-pass-search) (auth-source-pass--parse-data) (auth-source-pass--find-match-many): * lisp/autorevert.el (auto-revert-notify-rm-watch): * lisp/buff-menu.el (Buffer-menu-unmark-all-buffers) (Buffer-menu-group-by-root): * lisp/calendar/parse-time.el (parse-iso8601-time-string): * lisp/cedet/pulse.el (pulse-tick): * lisp/comint.el (comint--fontify-input-ppss-flush-indirect) (comint--intersect-regions): * lisp/completion-preview.el (completion-preview--try-table) (completion-preview--capf-wrapper, completion-preview--update): * lisp/cus-edit.el (setopt--set) (custom-dirlocals-maybe-update-cons, custom-dirlocals-validate): * lisp/custom.el (load-theme): * lisp/descr-text.el (describe-char): * lisp/desktop.el (desktop--emacs-pid-running-p): * lisp/dired-x.el (menu): * lisp/dired.el (dired-font-lock-keywords) (dired-insert-directory, dired--insert-disk-space, dired-mode): * lisp/dnd.el (dnd-handle-multiple-urls): * lisp/dom.el (dom-remove-attribute): * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): * lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare): * lisp/emacs-lisp/comp-common.el (comp-function-type-spec): * lisp/emacs-lisp/comp-cstr.el (comp--all-classes) (comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem) (comp-cstr-intersection-no-mem, comp-cstr-fixnum-p) (comp-cstr-type-p): * lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install) (native--compile-async): * lisp/emacs-lisp/comp.el (comp--get-function-cstr) (comp--function-pure-p, comp--intern-func-in-ctxt) (comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar) (comp--add-call-cstr, comp--compute-dominator-tree) (comp--dom-tree-walker, comp--ssa-rename) (comp--function-call-maybe-fold, comp--fwprop-call) (comp--call-optim-func): * lisp/emacs-lisp/edebug.el (edebug-global-prefix) (edebug-remove-instrumentation): * lisp/emacs-lisp/eieio.el (initialize-instance): * lisp/emacs-lisp/ert-x.el (ert-resource-directory): * lisp/emacs-lisp/ert.el (ert--expand-should-1) (ert-test-location, ert-write-junit-test-report) (ert-test--erts-test): * lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string) (icons--create): * lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p): * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--make-autoload) (loaddefs-generate--parse-file): * lisp/emacs-lisp/multisession.el (multisession-edit-mode--revert, multisession-edit-value): * lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data) (package-vc--version, package-vc--clone): * lisp/emacs-lisp/package.el (package--reload-previously-loaded): * lisp/emacs-lisp/pp.el (pp--insert-lisp): * lisp/emacs-lisp/subr-x.el (add-display-text-property): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-print): * lisp/emacs-lisp/timer.el (run-at-time): * lisp/emacs-lisp/vtable.el (vtable-goto-table) (vtable-goto-column, vtable-update-object, vtable--insert-line) (vtable--compute-widths, vtable--make-keymap): * lisp/emacs-lisp/warnings.el (display-warning): * lisp/epa-file.el (epa-file-insert-file-contents): * lisp/epa.el (epa-show-key): * lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt) (PRIVMSG, erc--get-isupport-entry): * lisp/erc/erc-button.el (erc-button-add-nickname-buttons) (erc--button-next): * lisp/erc/erc-common.el (erc--find-group): * lisp/erc/erc-fill.el (erc-fill, erc-fill-static) (erc-fill--wrap-escape-hidden-speaker) (erc-fill--wrap-unmerge-on-date-stamp) (erc-fill--wrap-massage-initial-message-post-clear) (erc-fill-wrap, erc-fill--wrap-rejigger-region): * lisp/erc/erc-goodies.el (erc--scrolltobottom-all) (erc--keep-place-indicator-on-window-buffer-change) (keep-place-indicator, erc--keep-place-indicator-adjust-on-clear) (erc-keep-place-move, erc--command-indicator-display): * lisp/erc/erc-ibuffer.el (erc-members): * lisp/erc/erc-join.el (erc-join--remove-requested-channel) (erc-autojoin--join): * lisp/erc/erc-networks.el (erc-networks--id-qualifying-init-parts, erc-networks--id-reload) (erc-networks--id-ensure-comparable) (erc-networks--reclaim-orphaned-target-buffers) (erc-networks--server-select): * lisp/erc/erc-nicks.el (erc-nicks-invert) (erc-nicks--redirect-face-widget-link, erc-nicks--highlight) (erc-nicks--highlight-button) (erc-nicks--list-faces-help-button-action, erc-nicks-list-faces) (erc-nicks-refresh, erc-nicks--colors-from-faces) (erc-nicks--track-prioritize) (erc-nicks--remember-face-for-track): * lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next) (erc--querypoll-on-352, erc--querypoll-send): * lisp/erc/erc-sasl.el (erc-sasl--read-password): * lisp/erc/erc-services.el (erc-services-issue-ghost-and-retry-nick): * lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar) (erc-speedbar-toggle-nicknames-window-lock) (erc-speedbar--compose-nicks-face): * lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect) (erc-stamp-prefix-log-filter, erc--conceal-prompt) (erc--insert-timestamp-left, erc-insert-timestamp-right) (erc-stamp--defer-date-insertion-on-post-modify) (erc-insert-timestamp-left-and-right) (erc-stamp--redo-right-stamp-post-clear) (erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps): * lisp/erc/erc-status-sidebar.el (bufbar) (erc-status-sidebar-prefer-target-as-name) (erc-status-sidebar-default-allsort, erc-status-sidebar-click): * lisp/erc/erc-track.el (erc-track--shortened-names-get) (erc-track--setup, erc-track--select-mode-line-face) (erc-track-modified-channels, erc-track--collect-faces-in) (erc-track--switch-buffer, erc-track--replace-killed-buffer): * lisp/erc/erc-truncate.el (erc-truncate--setup) (erc-truncate-buffer): * lisp/erc/erc.el (erc--ensure-query-member) (erc--ensure-query-members, erc--remove-channel-users-but) (erc--cusr-change-status, erc--find-mode, erc--update-modules) (erc-log-irc-protocol, erc--refresh-prompt) (erc--restore-important-text-props) (erc--order-text-properties-from-hash, erc-send-input-line) (erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY) (erc-cmd-BANLIST, erc--speakerize-nick) (erc--format-speaker-input-message, erc-channel-receive-names) (erc-send-current-line, erc-format-target-and/or-network) (erc-kill-buffer-function, erc-restore-text-properties) (erc--get-eq-comparable-cmd): * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which) (eshell-maybe-replace-by-alias): * lisp/eshell/em-glob.el (eshell-glob-convert): * lisp/eshell/em-pred.el (eshell-pred-user-or-group) (eshell-pred-file-time, eshell-pred-file-type) (eshell-pred-file-mode, eshell-pred-file-links) (eshell-pred-file-size): * lisp/eshell/em-prompt.el (eshell-forward-paragraph) (eshell-next-prompt): * lisp/eshell/esh-arg.el (eshell-resolve-current-argument): * lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which) (eshell-plain-command--which, eshell-plain-command): * lisp/eshell/esh-io.el (eshell-duplicate-handles) (eshell-protect-handles, eshell-get-target, eshell-close-target): * lisp/eshell/esh-proc.el (eshell-sentinel): * lisp/eshell/esh-var.el (eshell-parse-variable-ref) (eshell-get-variable, eshell-set-variable): * lisp/faces.el (face-at-point): * lisp/ffap.el (ffap-in-project): * lisp/filenotify.el (file-notify--rm-descriptor): * lisp/files-x.el (read-dir-locals-file) (connection-local-update-profile-variables) (connection-local-value): * lisp/files.el (file-remote-p, abbreviate-file-name) (set-auto-mode, hack-local-variables) (revert-buffer-restore-read-only): * lisp/find-dired.el (find-dired-sort-by-filename): * lisp/font-lock.el (font-lock--filter-keywords): * lisp/gnus/gnus-art.el (article-emojize-symbols): * lisp/gnus/gnus-int.el (gnus-close-server): * lisp/gnus/gnus-search.el (gnus-search-transform) (gnus-search-indexed-parse-output, gnus-search-server-to-engine): * lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url): * lisp/gnus/gnus.el (gnus-check-backend-function): * lisp/gnus/message.el (message-send-mail): * lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers): * lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article) (nnatom--read-article-or-group-authors, nnatom--read-publish) (nnatom--read-update, nnatom--read-links): * lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server) (nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article) (nnfeed-retrieve-headers, nnfeed--print-part) (nnfeed-request-article, nnfeed-request-group) (nnfeed-request-list, nnfeed--group-description) (nnfeed-request-group-description) (nnfeed-request-list-newsgroups, nnfeed-request-rename-group): * lisp/gnus/nnmh.el (nnmh-update-gnus-unreads): * lisp/help-fns.el (help-find-source) (help-fns--insert-menu-bindings, help-fns--mention-first-release) (help-fns--mention-shortdoc-groups) (help-fns--customize-variable-version) (help-fns--face-custom-version-info, describe-mode): * lisp/help-mode.el (help-make-xrefs): * lisp/help.el (help-key-description, help--describe-command): * lisp/hfy-cmap.el (htmlfontify-load-rgb-file): * lisp/ibuf-ext.el (ibuffer-jump-to-filter-group) (ibuffer-kill-filter-group, ibuffer-kill-line) (ibuffer-save-filter-groups, ibuffer-save-filters, filename) (basename, file-extension, ibuffer-diff-buffer-with-file-1) (ibuffer-mark-by-file-name-regexp) (ibuffer-mark-by-content-regexp): * lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen): * lisp/ibuffer.el (ibuffer-mouse-toggle-mark) (ibuffer-toggle-marks, ibuffer-mark-interactive) (ibuffer-compile-format, process, ibuffer-map-lines): * lisp/image.el (image--compute-map) (image--compute-original-map): * lisp/image/exif.el (exif-parse-buffer): * lisp/image/image-converter.el (image-convert-p, image-convert) (image-converter--find-converter): * lisp/image/image-dired-util.el (image-dired-file-name-at-point): * lisp/image/image-dired.el (image-dired-track-original-file) (image-dired--on-file-in-dired-buffer) (image-dired--with-thumbnail-buffer) (image-dired-jump-original-dired-buffer) (image-dired--slideshow-step, image-dired-display-image): * lisp/image/wallpaper.el (wallpaper--init-action-kill) (wallpaper--find-setter, wallpaper--find-command) (wallpaper--find-command-args, wallpaper--x-monitor-name): * lisp/info-look.el (info-lookup-interactive-arguments) (info-complete)::(:mode): * lisp/info.el (info-pop-to-buffer, Info-read-node-name-1): * lisp/international/emoji.el (emoji--adjust-displayable-1) (emoji--add-recent): * lisp/jsonrpc.el (jsonrpc--call-deferred) (jsonrpc--process-sentinel, jsonrpc--remove): * lisp/keymap.el (keymap-local-lookup): * lisp/mail/emacsbug.el (report-emacs-bug-hook) (submit-emacs-patch): * lisp/mail/ietf-drums.el (ietf-drums-parse-addresses): * lisp/mail/mailclient.el (mailclient-send-it): * lisp/mail/rfc6068.el (rfc6068-parse-mailto-url): * lisp/mail/undigest.el (rmail-digest-parse-mixed-mime): * lisp/minibuffer.el (completion-metadata-get) (completions--after-change) (minibuffer-visible-completions--filter): * lisp/net/browse-url.el (browse-url-url-at-point) (browse-url-file-url, browse-url-emacs): * lisp/net/dbus.el (dbus-byte-array-to-string) (dbus-monitor-goto-serial): * lisp/net/dictionary.el (dictionary-search): * lisp/net/eww.el (eww--download-directory) (eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit) (eww-follow-link, eww-read-alternate-url) (eww-copy-alternate-url): * lisp/net/goto-addr.el (goto-address-at-point): * lisp/net/mailcap.el (mailcap-mime-info): * lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string) (rcirc-kill-buffer-hook, rcirc-print, rcirc-when) (rcirc-color-attributes, rcirc-handler-NICK) (rcirc-handler-TAGMSG, rcirc-handler-BATCH): * lisp/net/shr.el (shr-descend, shr-adaptive-fill-function) (shr-correct-dom-case, shr-tag-a): * lisp/net/sieve.el (sieve-manage-quit): * lisp/outline.el (outline-cycle-buffer): * lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate): * lisp/proced.el (proced-auto-update-timer): * lisp/progmodes/bug-reference.el (bug-reference-try-setup-from-vc): * lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph): * lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset) (c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun): * lisp/progmodes/compile.el (compilation-error-properties) (compilation-find-file-1): * lisp/progmodes/eglot.el (eglot--check-object) (eglot--read-server, eglot-upgrade-eglot) (eglot-handle-notification, eglot--CompletionParams) (eglot-completion-at-point, eglot--sig-info) (eglot-register-capability): * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load) (elisp-eldoc-var-docstring-with-value): * lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test): * lisp/progmodes/flymake.el (flymake--update-eol-overlays) (flymake-eldoc-function): * lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom) (gdb-frame-handler): * lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring) (go-ts-mode--comment-on-previous-line-p) (go-ts-mode--get-test-regexp-at-point) (go-ts-mode-test-this-file): * lisp/progmodes/grep.el (lgrep, rgrep-default-command) (grep-file-at-point): * lisp/progmodes/perl-mode.el (perl--end-of-format-p): * lisp/progmodes/php-ts-mode.el (php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun): * lisp/progmodes/project.el (project--other-place-command) (project--find-default-from, project--transplant-file-name) (project-prefixed-buffer-name, project--remove-from-project-list) (project-prompt-project-name, project-remember-projects-under) (project--switch-project-command) (project-uniquify-dirname-transform, project-mode-line-format): * lisp/progmodes/python.el (python-font-lock-keywords-maximum-decoration) (python--treesit-fontify-union-types) (python-shell-get-process-name, python-shell-restart) (python-shell-completion-at-point, python-ffap-module-path) (python-util-comint-end-of-output-p, python--import-sources) (python-add-import, python-remove-import, python-fix-imports): * lisp/progmodes/xref.el (xref--add-log-current-defun): * lisp/repeat.el (repeat-echo-message-string): * lisp/saveplace.el (save-place-dired-hook): * lisp/server.el (server-save-buffers-kill-terminal): * lisp/shadowfile.el (shadow-make-fullname) (shadow-contract-file-name, shadow-define-literal-group): * lisp/shell.el (shell-highlight-undef-mode): * lisp/simple.el (command-completion-using-modes-p) (command-execute, file-user-uid, file-group-gid) (first-completion, last-completion, switch-to-completions): * lisp/startup.el (startup--load-user-init-file): * lisp/tab-line.el (tab-line-tabs-buffer-group-by-project): * lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer): * lisp/term/android-win.el (android-encode-select-string) (gui-backend-set-selection): * lisp/term/haiku-win.el (haiku-dnd-convert-string) (haiku-select-encode-xstring, haiku-select-encode-utf-8-string): * lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize): * lisp/textmodes/ispell.el (ispell-completion-at-point): * lisp/textmodes/sgml-mode.el (sgml-validate) (html-mode--complete-at-point): * lisp/textmodes/tex-mode.el (tex-recenter-output-buffer) (xref-backend-references): * lisp/thingatpt.el (thing-at-point-file-at-point) (thing-at-point-face-at-point): * lisp/thread.el (thread-list--get-status): * lisp/time.el (world-clock-copy-time-as-kill, world-clock): * lisp/touch-screen.el (touch-screen-handle-touch): * lisp/treesit.el (treesit-language-at, treesit-node-at) (treesit-node-on, treesit-buffer-root-node) (treesit-node-field-name, treesit-local-parsers-at) (treesit-local-parsers-on, treesit--cleanup-local-range-overlays) (treesit-font-lock-recompute-features) (treesit-font-lock-fontify-region, treesit-transpose-sexps) (treesit-add-log-current-defun, treesit-major-mode-setup) (treesit--explorer-refresh, treesit-install-language-grammar): * lisp/url/url.el (url-retrieve-synchronously): * lisp/vc/smerge-mode.el (smerge-diff): * lisp/vc/vc-dir.el (vc-dir): * lisp/vc/vc-dispatcher.el (vc-do-async-command): * lisp/vc/vc-git.el (vc-git-dir--branch-headers) (vc-git-dir--stash-headers, vc-git--log-edit-summary-check) (vc-git-stash-list): * lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset) (vc-clone): * lisp/visual-wrap.el (visual-wrap--apply-to-line): * lisp/wid-edit.el (widget-text) (widget-editable-list-insert-before): * lisp/window-tool-bar.el (window-tool-bar--keymap-entry-to-string): * lisp/window.el (display-buffer, display-buffer-full-frame) (window-point-context-set, window-point-context-use) (window-point-context-use-default-function): * lisp/xdg.el (xdg-current-desktop): * lisp/xwidget.el (xwidget-webkit-callback): * lisp/yank-media.el (yank-media--get-selection) (yank-media-types): * test/lisp/comint-tests.el (comint-tests/test-password-function): * test/lisp/completion-preview-tests.el (completion-preview-tests--capf): * test/lisp/cus-edit-tests.el (with-cus-edit-test): * test/lisp/erc/erc-scenarios-base-local-modules.el (-phony-sblm-): * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-post-modify): * test/lisp/erc/erc-services-tests.el (erc-services-tests--asp-parse-entry): * test/lisp/erc/erc-tests.el (erc-modules--internal-property) (erc--find-mode, erc-tests--update-modules): * test/lisp/erc/resources/erc-d/erc-d-i.el (erc-d-i--parse-message): * test/lisp/erc/resources/erc-d/erc-d-t.el (erc-d-t-kill-related-buffers, erc-d-t-with-cleanup): * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message--irc-parser-tests): * test/lisp/erc/resources/erc-d/erc-d-u.el (erc-d-u--read-exchange-slowly): * test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire) (erc-d--finalize-done, erc-d--command-handle-all): * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common-with-cleanup): * test/lisp/erc/resources/erc-tests-common.el (erc-tests--common-display-message) (erc-tests-common-create-subprocess): * test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058): * test/lisp/international/mule-tests.el (mule-cmds-tests--ucs-names-missing-names): * test/lisp/progmodes/python-tests.el (python-tests-get-shell-interpreter) (python-tests--get-interpreter-info): * test/lisp/progmodes/ruby-ts-mode-tests.el (ruby-ts-resource-file): * test/lisp/replace-tests.el (replace-tests-with-undo): * test/src/emacs-tests.el (emacs-tests--seccomp-debug): * test/src/process-tests.el (process-tests--emacs-command) (process-tests--emacs-binary, process-tests--dump-file): * test/src/treesit-tests.el (treesit--ert-test-defun-navigation): Replace use of the now-obsolete if-let and when-let.
964 lines
39 KiB
EmacsLisp
964 lines
39 KiB
EmacsLisp
;;; tabulated-list.el --- generic major mode for tabulated lists -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
|
|
|
|
;; Author: Chong Yidong <cyd@stupidchicken.com>
|
|
;; Keywords: extensions, lisp
|
|
;; Version: 1.0
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; 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.
|
|
|
|
;; 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.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; This file defines Tabulated List mode, a generic major mode for
|
|
;; displaying lists of tabulated data, intended for other major modes
|
|
;; to inherit from. It provides several utility routines, e.g. for
|
|
;; pretty-printing lines of tabulated data to fit into the appropriate
|
|
;; columns.
|
|
|
|
;; For usage information, see the documentation of `tabulated-list-mode'.
|
|
|
|
;; This package originated from Tom Tromey's Package Menu mode,
|
|
;; extended and generalized to be used by other modes.
|
|
|
|
;;; Code:
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
|
|
|
(defgroup tabulated-list nil
|
|
"Tabulated-list customization group."
|
|
:group 'convenience
|
|
:group 'display)
|
|
|
|
(defcustom tabulated-list-gui-sort-indicator-asc ?▼
|
|
"Indicator for columns sorted in ascending order, for GUI frames.
|
|
See `tabulated-list-tty-sort-indicator-asc' for the indicator used on
|
|
text-mode frames."
|
|
:group 'tabulated-list
|
|
:type 'character
|
|
:version "27.1")
|
|
|
|
(defcustom tabulated-list-gui-sort-indicator-desc ?▲
|
|
"Indicator for columns sorted in descending order, for GUI frames.
|
|
See `tabulated-list-tty-sort-indicator-desc' for the indicator used on
|
|
text-mode frames."
|
|
:group 'tabulated-list
|
|
:type 'character
|
|
:version "27.1")
|
|
|
|
(defcustom tabulated-list-tty-sort-indicator-asc ?v
|
|
"Indicator for columns sorted in ascending order, for text-mode frames.
|
|
See `tabulated-list-gui-sort-indicator-asc' for the indicator used on GUI
|
|
frames."
|
|
:group 'tabulated-list
|
|
:type 'character
|
|
:version "27.1")
|
|
|
|
(defcustom tabulated-list-tty-sort-indicator-desc ?^
|
|
"Indicator for columns sorted in ascending order, for text-mode frames.
|
|
See `tabulated-list-gui-sort-indicator-asc' for the indicator used on GUI
|
|
frames."
|
|
:group 'tabulated-list
|
|
:type 'character
|
|
:version "27.1")
|
|
|
|
(defface tabulated-list-fake-header
|
|
'((t :overline t :underline t :weight bold))
|
|
"Face used on fake header lines."
|
|
:version "27.1")
|
|
|
|
;; The reason `tabulated-list-format' and other variables are
|
|
;; permanent-local is to make it convenient to switch to a different
|
|
;; major mode, switch back, and have the original Tabulated List data
|
|
;; still valid. See, for example, ebuff-menu.el.
|
|
|
|
(defvar-local tabulated-list-format nil
|
|
"The format of the current Tabulated List mode buffer.
|
|
This should be a vector of elements (NAME WIDTH SORT . PROPS),
|
|
where:
|
|
- NAME is a string describing the column.
|
|
This is the label for the column in the header line.
|
|
Different columns must have non-`equal' names.
|
|
- WIDTH is the width to reserve for the column.
|
|
For the final element, its numerical value is ignored.
|
|
- SORT specifies how to sort entries by this column.
|
|
If nil, this column cannot be used for sorting.
|
|
If t, sort by comparing the string value printed in the column.
|
|
Otherwise, it should be a predicate function suitable for
|
|
`sort', accepting arguments with the same form as the elements
|
|
of `tabulated-list-entries'.
|
|
- PROPS is a plist of additional column properties.
|
|
Currently supported properties are:
|
|
- `:right-align': If non-nil, the column should be right-aligned.
|
|
- `:pad-right': Number of additional padding spaces to the
|
|
right of the column (defaults to 1 if omitted).")
|
|
(put 'tabulated-list-format 'permanent-local t)
|
|
|
|
(defvar-local tabulated-list-use-header-line t
|
|
"Whether the Tabulated List buffer should use a header line.")
|
|
|
|
(defvar-local tabulated-list-entries nil
|
|
"Entries displayed in the current Tabulated List buffer.
|
|
This should be either a function, or a list.
|
|
If a list, each element has the form (ID [DESC1 ... DESCN]),
|
|
where:
|
|
|
|
- ID is nil, or a Lisp object uniquely identifying this entry,
|
|
which is used to keep the cursor on the \"same\" entry when
|
|
rearranging the list. Comparison is done with `equal'.
|
|
|
|
- Each DESC is a column descriptor, one for each column
|
|
specified in `tabulated-list-format'. The descriptor DESC is
|
|
one of:
|
|
|
|
- A string, which is printed as-is, and must not contain any
|
|
newlines.
|
|
|
|
- An image descriptor (a list), which is used to insert an
|
|
image (see Info node `(elisp) Image Descriptors').
|
|
|
|
- A list (LABEL . PROPS), which means to use
|
|
`insert-text-button' to insert a text button with label
|
|
LABEL and button properties PROPS. LABEL must not contain
|
|
any newlines.
|
|
|
|
If `tabulated-list-entries' is a function, it is called with no
|
|
arguments and must return a list of the above form.")
|
|
(put 'tabulated-list-entries 'permanent-local t)
|
|
|
|
(defvar-local tabulated-list-groups nil
|
|
"Groups displayed in the current Tabulated List buffer.
|
|
This should be either a function, or a list.
|
|
If a list, each element has the form (GROUP-NAME ENTRIES),
|
|
where:
|
|
|
|
- GROUP-NAME is a group name as a string, which is displayed
|
|
at the top line of each group.
|
|
|
|
- ENTRIES is a list described in `tabulated-list-entries'.
|
|
|
|
If `tabulated-list-groups' is a function, it is called with no
|
|
arguments and must return a list of the above form.")
|
|
(put 'tabulated-list-groups 'permanent-local t)
|
|
|
|
(defvar-local tabulated-list-padding 0
|
|
"Number of characters preceding each Tabulated List mode entry.
|
|
By default, lines are padded with spaces, but you can use the
|
|
function `tabulated-list-put-tag' to change this.")
|
|
(put 'tabulated-list-padding 'permanent-local t)
|
|
|
|
(defvar tabulated-list-revert-hook nil
|
|
"Hook run before reverting a Tabulated List buffer.
|
|
This is commonly used to recompute `tabulated-list-entries'.")
|
|
|
|
(defvar-local tabulated-list-printer 'tabulated-list-print-entry
|
|
"Function for inserting a Tabulated List entry at point.
|
|
It is called with two arguments, ID and COLS. ID is a Lisp
|
|
object identifying the entry, and COLS is a vector of column
|
|
descriptors, as documented in `tabulated-list-entries'.")
|
|
|
|
(defvar tabulated-list--near-rows)
|
|
|
|
(defvar-local tabulated-list-sort-key nil
|
|
"Sort key for the current Tabulated List mode buffer.
|
|
If nil, no additional sorting is performed.
|
|
Otherwise, this should be a cons cell (NAME . FLIP).
|
|
NAME is a string matching one of the column names in
|
|
`tabulated-list-format' (the corresponding SORT entry in
|
|
`tabulated-list-format' then specifies how to sort). FLIP, if
|
|
non-nil, means to invert the resulting sort.")
|
|
(put 'tabulated-list-sort-key 'permanent-local t)
|
|
|
|
(defsubst tabulated-list-get-id (&optional pos)
|
|
"Return the entry ID of the Tabulated List entry at POS.
|
|
The value is an ID object from `tabulated-list-entries', or nil.
|
|
POS, if omitted or nil, defaults to point."
|
|
(get-text-property (or pos (point)) 'tabulated-list-id))
|
|
|
|
(defsubst tabulated-list-get-entry (&optional pos)
|
|
"Return the Tabulated List entry at POS.
|
|
The value is a vector of column descriptors, or nil if there is
|
|
no entry at POS. POS, if omitted or nil, defaults to point."
|
|
(get-text-property (or pos (point)) 'tabulated-list-entry))
|
|
|
|
(defun tabulated-list-put-tag (tag &optional advance)
|
|
"Put TAG in the padding area of the current line.
|
|
TAG should be a string, with length <= `tabulated-list-padding'.
|
|
If ADVANCE is non-nil, move forward by one line afterwards."
|
|
(unless (stringp tag)
|
|
(error "Invalid argument to `tabulated-list-put-tag'"))
|
|
(unless (> tabulated-list-padding 0)
|
|
(error "Unable to tag the current line"))
|
|
(save-excursion
|
|
(beginning-of-line)
|
|
(when (tabulated-list-get-entry)
|
|
(let ((beg (point))
|
|
(inhibit-read-only t))
|
|
(forward-char tabulated-list-padding)
|
|
(insert-and-inherit
|
|
(let ((width (string-width tag)))
|
|
(if (<= width tabulated-list-padding)
|
|
(concat tag
|
|
(make-string (- tabulated-list-padding width) ?\s))
|
|
(truncate-string-to-width tag tabulated-list-padding))))
|
|
(delete-region beg (+ beg tabulated-list-padding)))))
|
|
(if advance
|
|
(forward-line)))
|
|
|
|
(defun tabulated-list-clear-all-tags ()
|
|
"Clear all tags from the padding area in the current buffer."
|
|
(unless (> tabulated-list-padding 0)
|
|
(error "There can be no tags in current buffer"))
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(let ((inhibit-read-only t)
|
|
;; Match non-space in the first n characters.
|
|
(re (format "^ \\{0,%d\\}[^ ]" (1- tabulated-list-padding)))
|
|
(empty (make-string tabulated-list-padding ? )))
|
|
(while (re-search-forward re nil 'noerror)
|
|
(tabulated-list-put-tag empty)))))
|
|
|
|
(defvar-keymap tabulated-list-mode-map
|
|
:doc "Local keymap for `tabulated-list-mode' buffers."
|
|
:parent (make-composed-keymap button-buffer-map
|
|
special-mode-map)
|
|
"n" #'next-line
|
|
"p" #'previous-line
|
|
"M-<left>" #'tabulated-list-previous-column
|
|
"M-<right>" #'tabulated-list-next-column
|
|
"S" #'tabulated-list-sort
|
|
"}" #'tabulated-list-widen-current-column
|
|
"{" #'tabulated-list-narrow-current-column
|
|
"<follow-link>" 'mouse-face
|
|
"<mouse-2>" #'mouse-select-window)
|
|
|
|
(defvar-keymap tabulated-list-sort-button-map
|
|
:doc "Local keymap for `tabulated-list-mode' sort buttons."
|
|
"<header-line> <mouse-1>" #'tabulated-list-col-sort
|
|
"<header-line> <mouse-2>" #'tabulated-list-col-sort
|
|
"<mouse-1>" #'tabulated-list-col-sort
|
|
"<mouse-2>" #'tabulated-list-col-sort
|
|
"RET" #'tabulated-list-sort
|
|
"<follow-link>" 'mouse-face)
|
|
|
|
(defun tabulated-list-make-glyphless-char-display-table ()
|
|
"Make the `glyphless-char-display' table used for text-mode frames.
|
|
This table is used for displaying the sorting indicators, see
|
|
variables `tabulated-list-tty-sort-indicator-asc' and
|
|
`tabulated-list-tty-sort-indicator-desc' for more information."
|
|
(let ((table (make-char-table 'glyphless-char-display nil)))
|
|
(set-char-table-parent table glyphless-char-display)
|
|
(aset table
|
|
tabulated-list-gui-sort-indicator-desc
|
|
(cons nil (char-to-string tabulated-list-tty-sort-indicator-desc)))
|
|
(aset table
|
|
tabulated-list-gui-sort-indicator-asc
|
|
(cons nil (char-to-string tabulated-list-tty-sort-indicator-asc)))
|
|
table))
|
|
|
|
(defvar tabulated-list--header-string nil
|
|
"Holds the header if `tabulated-list-use-header-line' is nil.
|
|
Populated by `tabulated-list-init-header'.")
|
|
(defvar tabulated-list--header-overlay nil)
|
|
|
|
(define-obsolete-function-alias 'tabulated-list-line-number-width
|
|
'header-line-indent--line-number-width "29.1")
|
|
(define-obsolete-function-alias 'tabulated-list-watch-line-number-width
|
|
'header-line-indent--watch-line-number-width "29.1")
|
|
(define-obsolete-function-alias 'tabulated-list-window-scroll-function
|
|
'header-line-indent--window-scroll-function "29.1")
|
|
|
|
(defun tabulated-list-init-header ()
|
|
"Set up header line for the Tabulated List buffer."
|
|
;; FIXME: Should share code with tabulated-list-print-col!
|
|
(let* ((x (max tabulated-list-padding 0))
|
|
(button-props `(help-echo "Click to sort by column"
|
|
mouse-face header-line-highlight
|
|
keymap ,tabulated-list-sort-button-map))
|
|
(len (length tabulated-list-format))
|
|
;; Pre-compute width for available-space compution.
|
|
(hcols (mapcar #'car tabulated-list-format))
|
|
(tabulated-list--near-rows (list hcols hcols))
|
|
(cols nil))
|
|
(push (propertize " " 'display
|
|
`(space :align-to (+ header-line-indent-width ,x)))
|
|
cols)
|
|
(dotimes (n len)
|
|
(let* ((col (aref tabulated-list-format n))
|
|
(not-last-col (< n (1- len)))
|
|
(label (nth 0 col))
|
|
(lablen (length label))
|
|
(pname label)
|
|
(width (nth 1 col))
|
|
(props (nthcdr 3 col))
|
|
(pad-right (or (plist-get props :pad-right) 1))
|
|
(right-align (plist-get props :right-align))
|
|
(next-x (+ x pad-right width))
|
|
(available-space
|
|
(and not-last-col
|
|
(if right-align
|
|
width
|
|
(tabulated-list--available-space width n)))))
|
|
(when (and (>= lablen 3)
|
|
not-last-col
|
|
(> lablen available-space))
|
|
(setq label (truncate-string-to-width label available-space
|
|
nil nil t)))
|
|
(push
|
|
(cond
|
|
;; An unsortable column
|
|
((not (nth 2 col))
|
|
(propertize label 'tabulated-list-column-name pname))
|
|
;; The selected sort column
|
|
((equal (car col) (car tabulated-list-sort-key))
|
|
(apply 'propertize
|
|
(concat label
|
|
(cond
|
|
((and (< lablen 3) not-last-col) "")
|
|
((cdr tabulated-list-sort-key)
|
|
(format " %c"
|
|
tabulated-list-gui-sort-indicator-desc))
|
|
(t (format " %c"
|
|
tabulated-list-gui-sort-indicator-asc))))
|
|
'face 'bold
|
|
'tabulated-list-column-name pname
|
|
button-props))
|
|
;; Unselected sortable column.
|
|
(t (apply 'propertize label
|
|
'tabulated-list-column-name pname
|
|
button-props)))
|
|
cols)
|
|
(when right-align
|
|
(let ((shift (- width (string-width (car cols)))))
|
|
(when (> shift 0)
|
|
(setq cols
|
|
(cons (car cols)
|
|
(cons
|
|
(propertize
|
|
(make-string shift ?\s)
|
|
'display
|
|
`(space :align-to
|
|
(+ header-line-indent-width ,(+ x shift))))
|
|
(cdr cols))))
|
|
(setq x (+ x shift)))))
|
|
(if (>= pad-right 0)
|
|
(push (propertize
|
|
" "
|
|
'display `(space :align-to
|
|
(+ header-line-indent-width ,next-x))
|
|
'face 'fixed-pitch)
|
|
cols))
|
|
(setq x next-x)))
|
|
(setq cols (apply 'concat (nreverse cols)))
|
|
(if tabulated-list-use-header-line
|
|
(setq header-line-format (list "" 'header-line-indent cols))
|
|
(setq-local tabulated-list--header-string cols))))
|
|
|
|
(defun tabulated-list-print-fake-header ()
|
|
"Insert a fake Tabulated List \"header line\" at the start of the buffer.
|
|
Do nothing if `tabulated-list--header-string' is nil."
|
|
(when tabulated-list--header-string
|
|
(goto-char (point-min))
|
|
(let ((inhibit-read-only t))
|
|
(insert tabulated-list--header-string "\n")
|
|
(if tabulated-list--header-overlay
|
|
(move-overlay tabulated-list--header-overlay (point-min) (point))
|
|
(setq-local tabulated-list--header-overlay
|
|
(make-overlay (point-min) (point)))
|
|
(overlay-put tabulated-list--header-overlay 'fake-header t)
|
|
(overlay-put tabulated-list--header-overlay
|
|
'face 'tabulated-list-fake-header)))))
|
|
|
|
(defsubst tabulated-list-header-overlay-p (&optional pos)
|
|
"Return non-nil if there is a fake header.
|
|
Optional arg POS is a buffer position where to look for a fake header;
|
|
defaults to `point-min'."
|
|
(seq-find (lambda (o) (overlay-get o 'fake-header))
|
|
(overlays-at (or pos (point-min)))))
|
|
|
|
(defun tabulated-list-revert (&rest _ignored)
|
|
"The `revert-buffer-function' for `tabulated-list-mode'.
|
|
It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'."
|
|
(interactive)
|
|
(unless (derived-mode-p 'tabulated-list-mode)
|
|
(error "The current buffer is not in Tabulated List mode"))
|
|
(run-hooks 'tabulated-list-revert-hook)
|
|
(tabulated-list-print t))
|
|
|
|
(defun tabulated-list--column-number (name)
|
|
(let ((len (length tabulated-list-format))
|
|
(n 0)
|
|
found)
|
|
(while (and (< n len) (null found))
|
|
(if (equal (car (aref tabulated-list-format n)) name)
|
|
(setq found n))
|
|
(setq n (1+ n)))
|
|
(or found
|
|
(error "No column named %s" name))))
|
|
|
|
(defun tabulated-list--get-sorter ()
|
|
"Return a sorting predicate for the current tabulated-list.
|
|
Return nil if `tabulated-list-sort-key' specifies an unsortable
|
|
column. Negate the predicate that would be returned if
|
|
`tabulated-list-sort-key' has a non-nil cdr."
|
|
(when (and tabulated-list-sort-key
|
|
(car tabulated-list-sort-key))
|
|
(let* ((sort-column (car tabulated-list-sort-key))
|
|
(n (tabulated-list--column-number sort-column))
|
|
(sorter (nth 2 (aref tabulated-list-format n))))
|
|
(when (eq sorter t); Default sorter checks column N:
|
|
(setq sorter (lambda (A B)
|
|
(let ((a (aref (cadr A) n))
|
|
(b (aref (cadr B) n)))
|
|
(string< (if (stringp a) a (car a))
|
|
(if (stringp b) b (car b)))))))
|
|
;; Reversed order.
|
|
(if (cdr tabulated-list-sort-key)
|
|
(lambda (a b) (funcall sorter b a))
|
|
sorter))))
|
|
|
|
(defsubst tabulated-list--col-local-max-widths (col)
|
|
"Return maximum entry widths at column COL around current row.
|
|
Check the current row, the previous one and the next row."
|
|
(apply #'max (mapcar (lambda (x)
|
|
(let ((nt (elt x col)))
|
|
(string-width (if (stringp nt) nt (car nt)))))
|
|
tabulated-list--near-rows)))
|
|
|
|
(defun tabulated-list-print (&optional remember-pos update)
|
|
"Populate the current Tabulated List mode buffer.
|
|
This sorts the `tabulated-list-entries' list if sorting is
|
|
specified by `tabulated-list-sort-key'. It then erases the
|
|
buffer and inserts the entries with `tabulated-list-printer'.
|
|
|
|
If `tabulated-list-groups' is non-nil, each group of entries
|
|
is printed and sorted separately.
|
|
|
|
Optional argument REMEMBER-POS, if non-nil, means to move point
|
|
to the entry with the same ID element as the current line.
|
|
|
|
Non-nil UPDATE argument means to use an alternative printing
|
|
method which is faster if most entries haven't changed since the
|
|
last print. The only difference in outcome is that tags will not
|
|
be removed from entries that haven't changed (see
|
|
`tabulated-list-put-tag'). Don't use this immediately after
|
|
changing `tabulated-list-sort-key'."
|
|
(let ((inhibit-read-only t)
|
|
(groups (if (functionp tabulated-list-groups)
|
|
(funcall tabulated-list-groups)
|
|
tabulated-list-groups))
|
|
(entries (if (functionp tabulated-list-entries)
|
|
(funcall tabulated-list-entries)
|
|
tabulated-list-entries))
|
|
(sorter (tabulated-list--get-sorter))
|
|
entry-id saved-pt saved-col)
|
|
(and remember-pos
|
|
(setq entry-id (tabulated-list-get-id))
|
|
(setq saved-col (current-column)))
|
|
;; Sort the entries, if necessary.
|
|
(when sorter
|
|
(if groups
|
|
(setq groups
|
|
(mapcar (lambda (group)
|
|
(cons (car group) (sort (cdr group) sorter)))
|
|
groups))
|
|
(setq entries (sort entries sorter))))
|
|
(unless (functionp tabulated-list-groups)
|
|
(setq tabulated-list-groups groups))
|
|
(unless (functionp tabulated-list-entries)
|
|
(setq tabulated-list-entries entries))
|
|
;; Without a sorter, we have no way to just update.
|
|
(when (and update (not sorter))
|
|
(setq update nil))
|
|
(if update (goto-char (point-min))
|
|
;; Redo the buffer, unless we're just updating.
|
|
(erase-buffer)
|
|
(unless tabulated-list-use-header-line
|
|
(tabulated-list-print-fake-header)))
|
|
;; Finally, print the resulting list.
|
|
(if groups
|
|
(dolist (group groups)
|
|
(insert (car group) ?\n)
|
|
(when-let* ((saved-pt-new (tabulated-list-print-entries
|
|
(cdr group) sorter update entry-id)))
|
|
(setq saved-pt saved-pt-new)))
|
|
(setq saved-pt (tabulated-list-print-entries
|
|
entries sorter update entry-id)))
|
|
(when update
|
|
(delete-region (point) (point-max)))
|
|
(set-buffer-modified-p nil)
|
|
;; If REMEMBER-POS was specified, move to the "old" location.
|
|
(if saved-pt
|
|
(progn (goto-char saved-pt)
|
|
(move-to-column saved-col))
|
|
(goto-char (point-min)))))
|
|
|
|
(defun tabulated-list-print-entries (entries sorter update entry-id)
|
|
(let (saved-pt)
|
|
(while entries
|
|
(let* ((elt (car entries))
|
|
(tabulated-list--near-rows
|
|
(list
|
|
(or (tabulated-list-get-entry (pos-bol 0)) (cadr elt))
|
|
(cadr elt)
|
|
(or (cadr (cadr entries)) (cadr elt))))
|
|
(id (car elt)))
|
|
(and entry-id
|
|
(equal entry-id id)
|
|
(setq entry-id nil
|
|
saved-pt (point)))
|
|
;; If the buffer is empty, simply print each elt.
|
|
(if (or (not update) (eobp))
|
|
(apply tabulated-list-printer elt)
|
|
(while (let ((local-id (tabulated-list-get-id)))
|
|
;; If we find id, then nothing to update.
|
|
(cond ((equal id local-id)
|
|
(forward-line 1)
|
|
nil)
|
|
;; If this entry sorts after id (or it's the
|
|
;; end), then just insert id and move on.
|
|
((or (not local-id)
|
|
(funcall sorter elt
|
|
;; FIXME: Might be faster if
|
|
;; don't construct this list.
|
|
(list local-id (tabulated-list-get-entry))))
|
|
(apply tabulated-list-printer elt)
|
|
nil)
|
|
;; We find an entry that sorts before id,
|
|
;; it needs to be deleted.
|
|
(t t)))
|
|
(let ((old (point)))
|
|
(forward-line 1)
|
|
(delete-region old (point))))))
|
|
(setq entries (cdr entries)))
|
|
saved-pt))
|
|
|
|
(defun tabulated-list-print-entry (id cols)
|
|
"Insert a Tabulated List entry at point.
|
|
This is the default `tabulated-list-printer' function. ID is a
|
|
Lisp object identifying the entry to print, and COLS is a vector
|
|
of column descriptors."
|
|
(let ((beg (point))
|
|
(x (max tabulated-list-padding 0))
|
|
(ncols (length tabulated-list-format))
|
|
(inhibit-read-only t))
|
|
(if (> tabulated-list-padding 0)
|
|
(insert (make-string x ?\s)))
|
|
(let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506).
|
|
(or (bound-and-true-p tabulated-list--near-rows)
|
|
(list (or (tabulated-list-get-entry (pos-bol 0))
|
|
cols)
|
|
cols))))
|
|
(dotimes (n ncols)
|
|
(setq x (tabulated-list-print-col n (aref cols n) x))))
|
|
(insert ?\n)
|
|
;; Ever so slightly faster than calling `put-text-property' twice.
|
|
(add-text-properties
|
|
beg (point)
|
|
`(tabulated-list-id ,id tabulated-list-entry ,cols))))
|
|
|
|
(defun tabulated-list--available-space (width n)
|
|
(let* ((next-col-format (aref tabulated-list-format (1+ n)))
|
|
(next-col-right-align (plist-get (nthcdr 3 next-col-format)
|
|
:right-align))
|
|
(next-col-width (nth 1 next-col-format)))
|
|
(if next-col-right-align
|
|
(- (+ width next-col-width)
|
|
(min next-col-width
|
|
(tabulated-list--col-local-max-widths (1+ n))))
|
|
width)))
|
|
|
|
(defun tabulated-list-print-col (n col-desc x)
|
|
"Insert a specified Tabulated List entry at point.
|
|
N is the column number, COL-DESC is a column descriptor (see
|
|
`tabulated-list-entries'), and X is the column number at point.
|
|
Return the column number after insertion."
|
|
(let* ((format (aref tabulated-list-format n))
|
|
(name (nth 0 format))
|
|
(width (nth 1 format))
|
|
(props (nthcdr 3 format))
|
|
(pad-right (or (plist-get props :pad-right) 1))
|
|
(right-align (plist-get props :right-align))
|
|
(label (cond ((stringp col-desc) col-desc)
|
|
((eq (car col-desc) 'image) " ")
|
|
(t (car col-desc))))
|
|
(label-width (string-width label))
|
|
(help-echo (concat (car format) ": " label))
|
|
(opoint (point))
|
|
(not-last-col (< (1+ n) (length tabulated-list-format)))
|
|
(available-space (and not-last-col
|
|
(if right-align
|
|
width
|
|
(tabulated-list--available-space width n)))))
|
|
;; Truncate labels if necessary (except last column).
|
|
;; Don't truncate to `width' if the next column is align-right
|
|
;; and has some space left, truncate to `available-space' instead.
|
|
(when (and not-last-col
|
|
(> label-width available-space))
|
|
(setq label (truncate-string-to-width
|
|
label available-space nil nil t t)
|
|
label-width available-space))
|
|
(setq label (bidi-string-mark-left-to-right label))
|
|
(when (and right-align (> width label-width))
|
|
(let ((shift (- width label-width)))
|
|
(insert (propertize (make-string shift ?\s)
|
|
'display `(space :align-to ,(+ x shift))))
|
|
(setq width (- width shift))
|
|
(setq x (+ x shift))))
|
|
(cond ((stringp col-desc)
|
|
(insert (if (get-text-property 0 'help-echo label)
|
|
label
|
|
(propertize label 'help-echo help-echo))))
|
|
((eq (car col-desc) 'image)
|
|
(insert (propertize " "
|
|
'display col-desc
|
|
'help-echo help-echo)))
|
|
((apply 'insert-text-button label (cdr col-desc))))
|
|
(let ((next-x (+ x pad-right width)))
|
|
;; No need to append any spaces if this is the last column.
|
|
(when not-last-col
|
|
(when (> pad-right 0) (insert (make-string pad-right ?\s)))
|
|
(insert (propertize
|
|
(make-string (- width (min width label-width)) ?\s)
|
|
'display `(space :align-to ,next-x))))
|
|
(put-text-property opoint (point) 'tabulated-list-column-name name)
|
|
next-x)))
|
|
|
|
(defun tabulated-list-delete-entry ()
|
|
"Delete the Tabulated List entry at point.
|
|
Return a list (ID COLS), where ID is the ID of the deleted entry
|
|
and COLS is a vector of its column descriptors. Move point to
|
|
the beginning of the deleted entry. Return nil if there is no
|
|
entry at point.
|
|
|
|
This function only changes the buffer contents; it does not alter
|
|
`tabulated-list-entries'."
|
|
;; Assume that each entry occupies one line.
|
|
(let* ((id (tabulated-list-get-id))
|
|
(cols (tabulated-list-get-entry))
|
|
(inhibit-read-only t))
|
|
(when cols
|
|
(delete-region (pos-bol) (1+ (pos-eol)))
|
|
(list id cols))))
|
|
|
|
(defun tabulated-list-set-col (col desc &optional change-entry-data)
|
|
"Change the Tabulated List entry at point, setting COL to DESC.
|
|
COL is the column number to change, or the name of the column to change.
|
|
DESC is the new column descriptor, which is inserted via
|
|
`tabulated-list-print-col'.
|
|
|
|
If CHANGE-ENTRY-DATA is non-nil, modify the underlying entry data
|
|
by setting the appropriate slot of the vector originally used to
|
|
print this entry. If `tabulated-list-entries' has a list value,
|
|
this is the vector stored within it."
|
|
(let* ((opoint (point))
|
|
(eol (pos-eol))
|
|
(pos (pos-bol))
|
|
(id (tabulated-list-get-id pos))
|
|
(entry (tabulated-list-get-entry pos))
|
|
(prop 'tabulated-list-column-name)
|
|
(inhibit-read-only t)
|
|
name)
|
|
(cond ((numberp col)
|
|
(setq name (car (aref tabulated-list-format col))))
|
|
((stringp col)
|
|
(setq name col
|
|
col (tabulated-list--column-number col)))
|
|
(t
|
|
(error "Invalid column %s" col)))
|
|
(unless entry
|
|
(error "No Tabulated List entry at position %s" opoint))
|
|
(unless (equal (get-text-property pos prop) name)
|
|
(while (and (setq pos
|
|
(next-single-property-change pos prop nil eol))
|
|
(< pos eol)
|
|
(not (equal (get-text-property pos prop) name)))))
|
|
(when (< pos eol)
|
|
(delete-region pos (next-single-property-change pos prop nil eol))
|
|
(goto-char pos)
|
|
(let ((tabulated-list--near-rows
|
|
(list
|
|
(tabulated-list-get-entry (pos-bol 0))
|
|
entry
|
|
(or (tabulated-list-get-entry (pos-bol 2)) entry))))
|
|
(tabulated-list-print-col col desc (current-column)))
|
|
(if change-entry-data
|
|
(aset entry col desc))
|
|
(put-text-property pos (point) 'tabulated-list-id id)
|
|
(put-text-property pos (point) 'tabulated-list-entry entry)
|
|
(goto-char opoint))))
|
|
|
|
(defun tabulated-list-col-sort (&optional e)
|
|
"Sort Tabulated List entries by the column of the mouse click E."
|
|
(interactive "e")
|
|
(let* ((pos (event-start e))
|
|
(obj (posn-object pos)))
|
|
(with-current-buffer (window-buffer (posn-window pos))
|
|
(tabulated-list--sort-by-column-name
|
|
(get-text-property (if obj (cdr obj) (posn-point pos))
|
|
'tabulated-list-column-name
|
|
(car obj))))))
|
|
|
|
(defun tabulated-list-sort (&optional n)
|
|
"Sort Tabulated List entries by the column at point.
|
|
With a numeric prefix argument N, sort the Nth column.
|
|
|
|
If the numeric prefix is -1, restore order the list was
|
|
originally displayed in."
|
|
(interactive "P")
|
|
(when (and n
|
|
(or (>= n (length tabulated-list-format))
|
|
(< n -1)))
|
|
(user-error "Invalid column number"))
|
|
(if (equal n -1)
|
|
;; Restore original order.
|
|
(progn
|
|
(unless tabulated-list--original-order
|
|
(error "Order is already in original order"))
|
|
(setq tabulated-list-entries
|
|
(sort tabulated-list-entries
|
|
(lambda (e1 e2)
|
|
(< (gethash e1 tabulated-list--original-order)
|
|
(gethash e2 tabulated-list--original-order)))))
|
|
(setq tabulated-list-sort-key nil)
|
|
(tabulated-list-init-header)
|
|
(tabulated-list-print t))
|
|
;; Sort based on a column name.
|
|
(let ((name (if n
|
|
(car (aref tabulated-list-format n))
|
|
(get-text-property (point)
|
|
'tabulated-list-column-name))))
|
|
(if (nth 2 (assoc name (append tabulated-list-format nil)))
|
|
(tabulated-list--sort-by-column-name name)
|
|
(user-error "Cannot sort by %s" name)))))
|
|
|
|
(defun tabulated-list--sort-by-column-name (name)
|
|
(when (and name (derived-mode-p 'tabulated-list-mode))
|
|
(unless tabulated-list--original-order
|
|
;; Store the original order so that we can restore it later.
|
|
(setq tabulated-list--original-order (make-hash-table))
|
|
(cl-loop for elem in tabulated-list-entries
|
|
for i from 0
|
|
do (setf (gethash elem tabulated-list--original-order) i)))
|
|
;; Flip the sort order on a second click.
|
|
(if (equal name (car tabulated-list-sort-key))
|
|
(setcdr tabulated-list-sort-key
|
|
(not (cdr tabulated-list-sort-key)))
|
|
(setq tabulated-list-sort-key (cons name nil)))
|
|
(tabulated-list-init-header)
|
|
(tabulated-list-print t)))
|
|
|
|
(defun tabulated-list-widen-current-column (&optional n)
|
|
"Widen the current tabulated-list column by N chars.
|
|
Interactively, N is the prefix numeric argument, and defaults to
|
|
1."
|
|
(interactive "p")
|
|
(let ((start (current-column))
|
|
(entry (tabulated-list-get-entry))
|
|
(nb-cols (length tabulated-list-format))
|
|
(col-nb 0)
|
|
(total-width 0)
|
|
(found nil)
|
|
col-width)
|
|
(while (and (not found)
|
|
(< col-nb nb-cols))
|
|
(if (>= start
|
|
(setq total-width
|
|
(+ total-width
|
|
(max (setq col-width
|
|
(cadr (aref tabulated-list-format
|
|
col-nb)))
|
|
(let ((desc (aref entry col-nb)))
|
|
(string-width (if (stringp desc)
|
|
desc
|
|
(car desc)))))
|
|
(or (plist-get (nthcdr 3 (aref tabulated-list-format
|
|
col-nb))
|
|
:pad-right)
|
|
1))))
|
|
(setq col-nb (1+ col-nb))
|
|
(setq found t)
|
|
;; `tabulated-list-format' may be a constant (sharing list
|
|
;; structures), so copy it before mutating.
|
|
(setq tabulated-list-format (copy-tree tabulated-list-format t))
|
|
(setf (cadr (aref tabulated-list-format col-nb))
|
|
(max 1 (+ col-width n)))
|
|
(tabulated-list-print t)
|
|
(tabulated-list-init-header)))))
|
|
|
|
(defun tabulated-list-narrow-current-column (&optional n)
|
|
"Narrow the current tabulated list column by N chars.
|
|
Interactively, N is the prefix numeric argument, and defaults to
|
|
1."
|
|
(interactive "p")
|
|
(tabulated-list-widen-current-column (- n)))
|
|
|
|
(defun tabulated-list-next-column (&optional arg)
|
|
"Go to the start of the next column after point on the current line.
|
|
If ARG is provided, move that many columns."
|
|
(interactive "p")
|
|
(dotimes (_ (or arg 1))
|
|
(let ((next (or (next-single-property-change
|
|
(point) 'tabulated-list-column-name)
|
|
(point-max))))
|
|
(when (<= next (line-end-position))
|
|
(goto-char next)))))
|
|
|
|
(defun tabulated-list-previous-column (&optional arg)
|
|
"Go to the start of the column point is in on the current line.
|
|
If ARG is provided, move that many columns."
|
|
(interactive "p")
|
|
(dotimes (_ (or arg 1))
|
|
(let ((prev (or (previous-single-property-change
|
|
(point) 'tabulated-list-column-name)
|
|
1)))
|
|
(unless (< prev (pos-bol))
|
|
(goto-char prev)))))
|
|
|
|
;;; The mode definition:
|
|
|
|
(defvar tabulated-list--original-order nil)
|
|
|
|
(define-derived-mode tabulated-list-mode special-mode "Tabulated"
|
|
"Generic major mode for browsing a list of items.
|
|
This mode is usually not used directly; instead, other major
|
|
modes are derived from it, using `define-derived-mode'.
|
|
|
|
In this major mode, the buffer is divided into multiple columns,
|
|
which are labeled using the header line. Each non-empty line
|
|
belongs to one \"entry\", and the entries can be sorted according
|
|
to their column values.
|
|
|
|
An inheriting mode should usually do the following in their body:
|
|
|
|
- Set `tabulated-list-format', specifying the column format.
|
|
- Set `tabulated-list-revert-hook', if the buffer contents need
|
|
to be specially recomputed prior to `revert-buffer'.
|
|
- Maybe set a `tabulated-list-entries' function (see below).
|
|
- Maybe set `tabulated-list-printer' (see below).
|
|
- Maybe set `tabulated-list-padding'.
|
|
- Call `tabulated-list-init-header' to initialize `header-line-format'
|
|
according to `tabulated-list-format'.
|
|
|
|
An inheriting mode is usually accompanied by a \"list-FOO\"
|
|
command (e.g. `list-packages', `list-processes'). This command
|
|
creates or switches to a buffer and enables the major mode in
|
|
that buffer. If `tabulated-list-entries' is not a function, the
|
|
command should initialize it to a list of entries for displaying.
|
|
Finally, it should call `tabulated-list-print'.
|
|
|
|
`tabulated-list-print' calls the printer function specified by
|
|
`tabulated-list-printer', once for each entry. The default
|
|
printer is `tabulated-list-print-entry', but a mode that keeps
|
|
data in an ewoc may instead specify a printer function (e.g., one
|
|
that calls `ewoc-enter-last'), with `tabulated-list-print-entry'
|
|
as the ewoc pretty-printer."
|
|
(setq-local truncate-lines t)
|
|
(setq-local buffer-undo-list t)
|
|
(setq-local revert-buffer-function #'tabulated-list-revert)
|
|
(setq-local glyphless-char-display
|
|
(tabulated-list-make-glyphless-char-display-table))
|
|
(setq-local text-scale-remap-header-line t)
|
|
(setq-local tabulated-list--original-order nil)
|
|
;; Avoid messing up the entries' display just because the first
|
|
;; column of the first entry happens to begin with a R2L letter.
|
|
(setq bidi-paragraph-direction 'left-to-right)
|
|
(header-line-indent-mode))
|
|
|
|
(put 'tabulated-list-mode 'mode-class 'special)
|
|
|
|
;;; Tabulated list groups
|
|
|
|
(defun tabulated-list-groups (entries metadata)
|
|
"Make a flat list of groups from list of ENTRIES.
|
|
Return the data structure suitable to be set to the variable
|
|
`tabulated-list-groups'. METADATA is a property list with two keys:
|
|
PATH-FUNCTION is a function to put an entry from ENTRIES to the tree
|
|
\(see `tabulated-list-groups-categorize' for more information);
|
|
SORT-FUNCTION is a function to sort groups in the tree
|
|
\(see `tabulated-list-groups-sort' for more information)."
|
|
(let* ((path-function (plist-get metadata :path-function))
|
|
(sort-function (plist-get metadata :sort-function))
|
|
(tree (tabulated-list-groups-categorize entries path-function)))
|
|
(when sort-function
|
|
(setq tree (tabulated-list-groups-sort tree sort-function)))
|
|
(tabulated-list-groups-flatten tree)))
|
|
|
|
(defun tabulated-list-groups-categorize (entries path-function)
|
|
"Make a tree of groups from list of ENTRIES.
|
|
On each entry from ENTRIES apply PATH-FUNCTION that should return a list of
|
|
paths that the entry has on the group tree that means that every entry
|
|
can belong to multiple categories. Every path is a list of strings
|
|
where every string is an outline heading at increasing level of deepness."
|
|
(let ((tree nil)
|
|
(hash (make-hash-table :test #'equal)))
|
|
(cl-labels
|
|
((trie-add (list tree)
|
|
(when list
|
|
(setf (alist-get (car list) tree nil nil #'equal)
|
|
(trie-add (cdr list)
|
|
(alist-get (car list) tree nil nil #'equal)))
|
|
tree))
|
|
(trie-get (tree path)
|
|
(mapcar (lambda (elt)
|
|
(cons (car elt)
|
|
(if (cdr elt)
|
|
(trie-get (cdr elt) (cons (car elt) path))
|
|
(apply #'vector (nreverse
|
|
(gethash (reverse
|
|
(cons (car elt) path))
|
|
hash))))))
|
|
(reverse tree))))
|
|
(dolist (entry entries)
|
|
(dolist (path (funcall path-function entry))
|
|
(unless (gethash path hash)
|
|
(setq tree (trie-add path tree)))
|
|
(cl-pushnew entry (gethash path hash))))
|
|
(trie-get tree nil))))
|
|
|
|
(defun tabulated-list-groups-sort (tree sort-function &optional level)
|
|
"Sort TREE using the sort function SORT-FUN."
|
|
(unless level (setq level 1))
|
|
(mapcar (lambda (elt)
|
|
(if (vectorp (cdr elt))
|
|
elt
|
|
(cons (car elt) (tabulated-list-groups-sort
|
|
(cdr elt) sort-function (1+ level)))))
|
|
(funcall sort-function tree level)))
|
|
|
|
(defun tabulated-list-groups-flatten (tree)
|
|
"Flatten multi-level TREE to single level."
|
|
(let ((header "") acc)
|
|
(cl-labels
|
|
((flatten (tree level)
|
|
(mapcar (lambda (elt)
|
|
(setq header (format "%s%s %s\n" header
|
|
(make-string level ?*)
|
|
(car elt)))
|
|
(cond
|
|
((vectorp (cdr elt))
|
|
(setq acc (cons (cons (string-trim-right header)
|
|
(append (cdr elt) nil))
|
|
acc))
|
|
(setq header ""))
|
|
(t (flatten (cdr elt) (1+ level)))))
|
|
tree)))
|
|
(flatten tree 1)
|
|
(nreverse acc))))
|
|
|
|
(provide 'tabulated-list)
|
|
|
|
;;; tabulated-list.el ends here
|