-
Notifications
You must be signed in to change notification settings - Fork 0
/
nix3-section.el
61 lines (48 loc) · 2.05 KB
/
nix3-section.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;; nix3-section.el --- Magit sections -*- lexical-binding: t -*-
;; Copyright (C) 2022,2023 Akira Komamura
;; Author: Akira Komamura <[email protected]>
;; URL: https://github.com/emacs-twist/nix3.el
;; This file is not part of GNU Emacs.
;;; License:
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 2.1 of the License, or (at your option) any later version.
;;
;; This library 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
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;;; Commentary:
;; FIXME
;;; Code:
(require 'magit-section)
(defmacro nix3-section-with-keymap (map &rest body)
(declare (indent 1))
`(let ((start (point)))
(prog1 (progn
,@body)
(let ((ov (make-overlay start (point))))
(overlay-put ov 'keymap ,map)))))
(defmacro nix3-section--heading (body)
`(propertize ,body 'face 'magit-section-heading))
(defmacro nix3-section-dlist (indent-level &rest rows)
(declare (indent 1))
(let* ((width (1+ (cl-loop for header in (mapcar #'car rows)
maximize (length header))))
(indent-string (make-string indent-level ?\ ))
(th (format "%s%%-%ds" indent-string width)))
`(progn
,@(mapcar (pcase-lambda (`(,header ,visible ,exp))
`(when ,visible
(magit-insert-section ('row ,header)
(insert (nix3-section--heading (format ,th ,header)))
,exp
(newline))))
rows))))
(provide 'nix3-section)
;;; nix3-section.el ends here