Skip to content

Commit

Permalink
forge-tablist.el: Create new library from existing code
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Apr 21, 2024
1 parent 3691577 commit 2f05d51
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 65 deletions.
1 change: 1 addition & 0 deletions default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ELS += $(PKG)-gogs.el
ELS += $(PKG)-bitbucket.el
ELS += $(PKG)-semi.el
ELS += $(PKG)-commands.el
ELS += $(PKG)-tablist.el
ELS += $(PKG)-topics.el
ELS += $(PKG)-repos.el
ELCS = $(ELS:.el=.elc)
Expand Down
5 changes: 3 additions & 2 deletions lisp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ $(PKG)-gogs.elc: $(PKG).elc
$(PKG)-bitbucket.elc: $(PKG).elc
$(PKG)-semi.elc: $(PKG).elc
$(PKG)-commands.elc: $(PKG).elc
$(PKG)-topics.elc: $(PKG).elc
$(PKG)-repos.elc: $(PKG)-topics.elc
$(PKG)-list.elc: $(PKG).elc
$(PKG)-topics.elc: $(PKG)-tablist.elc
$(PKG)-repos.elc: $(PKG)-tablist.elc

%.elc: %.el
@printf "Compiling $<\n"
Expand Down
5 changes: 4 additions & 1 deletion lisp/forge-repos.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

;;; Code:

(require 'forge-topics)
(require 'hl-line)

(require 'forge-repo)
(require 'forge-tablist)

;;; Options

Expand Down
85 changes: 85 additions & 0 deletions lisp/forge-tablist.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
;;; forge-tablist.el --- Tabulated-list interface -*- lexical-binding:t -*-

;; Copyright (C) 2018-2024 Jonas Bernoulli

;; Author: Jonas Bernoulli <[email protected]>
;; Maintainer: Jonas Bernoulli <[email protected]>

;; SPDX-License-Identifier: GPL-3.0-or-later

;; This file 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.
;;
;; This file 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 this file. If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'tabulated-list)

(require 'forge)

(defvar-local forge--buffer-list-type nil)
(defvar-local forge--buffer-list-filter nil)
(defvar-local forge--buffer-list-global nil)

(defconst forge--tablist-columns-type
'(repeat
(list :tag "Column"
(string :tag "Header Label")
(choice :tag "Value source"
function
(symbol :tag "Object slot"))
(integer :tag "Column Width")
(choice :tag "Sort predicate"
(const :tag "Don't sort" nil)
(const :tag "Default" t)
function)
(plist :tag "Properties"
:key-type (choice :tag "Property"
(const :right-align)
(const :pad-right)
symbol)
:value-type (sexp :tag "Value")))))

(defvar-local forge--tabulated-list-columns nil)
(put 'forge--tabulated-list-columns 'permanent-local t)

(defvar-local forge--tabulated-list-query nil)
(put 'forge--tabulated-list-query 'permanent-local t)

(defun forge--tablist-refresh ()
(setq tabulated-list-format
(vconcat (mapcar (pcase-lambda (`(,name ,_get ,width ,sort ,props))
`(,name ,width ,sort . ,props))
forge--tabulated-list-columns)))
(tabulated-list-init-header)
(setq tabulated-list-entries
(mapcar
(lambda (obj)
(list (oref obj id)
(vconcat
(mapcar (pcase-lambda (`(,_name ,get ,_width ,_sort ,_props))
(let ((val (cond
((functionp get)
(funcall get obj))
((eq (car-safe get) 'repository)
(eieio-oref (forge-get-repository obj)
(cadr get)))
((eieio-oref obj get)))))
(cond ((stringp val) val)
((null val) "")
((format "%s" val)))))
forge--tabulated-list-columns))))
(funcall forge--tabulated-list-query))))

;;; _
(provide 'forge-tablist)
;;; forge-tablist.el ends here
64 changes: 2 additions & 62 deletions lisp/forge-topics.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
;;; Code:

(require 'hl-line)
(require 'tabulated-list)

(require 'forge)
(require 'forge-topic)
(require 'forge-tablist)

(defvar x-stretch-cursor)

Expand All @@ -39,25 +38,6 @@
:type 'hook
:options '(hl-line-mode))

(defconst forge--tablist-columns-type
'(repeat
(list :tag "Column"
(string :tag "Header Label")
(choice :tag "Value source"
function
(symbol :tag "Object slot"))
(integer :tag "Column Width")
(choice :tag "Sort predicate"
(const :tag "Don't sort" nil)
(const :tag "Default" t)
function)
(plist :tag "Properties"
:key-type (choice :tag "Property"
(const :right-align)
(const :pad-right)
symbol)
:value-type (sexp :tag "Value")))))

(defcustom forge-topic-list-columns
'(("#" forge--format-topic-slug 5 nil nil)
("Title" forge--format-topic-title+labels 35 nil nil))
Expand Down Expand Up @@ -150,47 +130,7 @@ label, cannot be changed independently of the color used in the
forges web interface."
:group 'forge-faces)

;;; Variables

(defvar-local forge--tabulated-list-columns nil)
(put 'forge--tabulated-list-columns 'permanent-local t)

(defvar-local forge--tabulated-list-query nil)
(put 'forge--tabulated-list-query 'permanent-local t)

(defvar-local forge--buffer-list-type nil)
(defvar-local forge--buffer-list-filter nil)
(defvar-local forge--buffer-list-global nil)

;;; Modes
;;;; Common

(defun forge--tablist-refresh ()
(setq tabulated-list-format
(vconcat (mapcar (pcase-lambda (`(,name ,_get ,width ,sort ,props))
`(,name ,width ,sort . ,props))
forge--tabulated-list-columns)))
(tabulated-list-init-header)
(setq tabulated-list-entries
(mapcar
(lambda (obj)
(list (oref obj id)
(vconcat
(mapcar (pcase-lambda (`(,_name ,get ,_width ,_sort ,_props))
(let ((val (cond
((functionp get)
(funcall get obj))
((eq (car-safe get) 'repository)
(eieio-oref (forge-get-repository obj)
(cadr get)))
((eieio-oref obj get)))))
(cond ((stringp val) val)
((null val) "")
((format "%s" val)))))
forge--tabulated-list-columns))))
(funcall forge--tabulated-list-query))))

;;;; Topics
;;; Mode

(defvar-keymap forge-topic-list-mode-map
:doc "Local keymap for Forge-Topic-List mode buffers."
Expand Down

0 comments on commit 2f05d51

Please sign in to comment.