summaryrefslogtreecommitdiff
path: root/lisp/guix-merge-upstream.el
blob: df1f69bb1031754e79736d7a330c9e71f0c948c4 (about) (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;;; guix-merge-upstream.el --- Misc function for Emacs Guix  -*- lexical-binding: t; -*-

;; Copyright (C) 2018  Oleg Pykhalov

;; Author: Oleg Pykhalov <go.wigust@gmail.com>
;; Keywords: local

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

;;; Commentary:

;; This package provides additional functionality in addition to Emacs
;; Guix.

;;; Code:

(defun guix-mu-next ()
  (interactive)
  (forward-sexp)
  (forward-char 2))

(defun guix-mu-prev ()
  (interactive)
  (backward-sexp))

(defun guix-mu-other-next ()
  (interactive)
  (other-window 1)
  (forward-sexp)
  (forward-char 2)
  (other-window 1))

(defun guix-mu-other-prev ()
  (interactive)
  (other-window 1)
  (backward-sexp)
  (other-window 1))

(defun guix-mu-kill-sexp ()
  (interactive)
  (kill-sexp)
  (let ((point (point)))
    (delete-region point (+ point 2))))

(defun guix-mu-other ()
  (interactive)
  (other-window 1))

(defun guix-mu-yank ()
  (interactive)
  (yank)
  (newline 2)
  (backward-sexp))

(defun guix-mu-copy ()
  (interactive)
  (guix-mu-kill-sexp)
  (other-window 1)
  (guix-mu-yank)
  (other-window 1))

(defun guix-mu-commit ()
  (interactive)
  (save-buffer)
  (let ((var (save-excursion
               (forward-char)
               (forward-sexp)
               (forward-char)
               (thing-at-point 'symbol)))
        (filename (buffer-file-name)))
    (call-interactively #'vc-next-action)
    (call-interactively #'vc-next-action)
    (insert "gnu: Add " var)
    (newline 2)
    (insert (format "* %s (%s): New public variable."
                    (f-relative filename
                                (f-expand (vc-git-root filename)))
                    var))
    (log-edit-done)))

(defun guix-mu-copy-and-commit ()
  (interactive)
  (guix-mu-kill-sexp)
  (other-window 1)
  (guix-mu-yank)
  (guix-mu-commit)
  (other-window 1))

(defun guix-mu-revert ()
  (interactive)
  (yes-or-no-p "Revert all changes ? ")
  (revert-buffer nil t)
  (other-window 1)
  (revert-buffer nil t)
  (other-window 1))

(defun guix-mu-hide-all ()
  (interactive)
  (let ((hs-hide-all-non-comment-function nil))
    (hs-hide-all)))

(defun guix-mu-search (package)
  "Search for a PACKAGE and return it."
  (interactive)
  (goto-char (point-min))
  (search-forward (concat "(define-public " package))
  (beginning-of-line)
  package)

(defun guix-mu-kill ()
  "Kill sexp and delete blank lines."
  (kill-sexp)
  (delete-blank-lines))

(defun guix-commit (package message comment)
  "Commit a PACKAGE with MESSAGE and COMMENT."
  (let* ((filename (buffer-file-name (current-buffer)))
         (relative (f-relative filename
                               (f-expand (vc-git-root filename)))))
    (call-interactively #'vc-next-action)
    (call-interactively #'vc-next-action)
    (insert (format "%s: %s\n\n"
                    (car (split-string relative "/")) message)
            (format "* %s (%s): %s" relative package comment))
    (call-interactively #'fill-paragraph)
    (log-edit-done)))

(defun guix-mu-foo ()
  (interactive)
  (let ((package (thing-at-point 'symbol)))
    (beginning-of-line)
    (kill-line 1)
    (with-current-buffer (get-buffer "emacs.scm<wigust>")
      (guix-mu-search package)
      (guix-mu-kill)
      (save-buffer)
      (guix-commit package
                   (format "Merge %s to Guix package collection."
                           package)
                   (format "Merge %s to Guix package collection."
                           package)))
    (with-current-buffer (get-buffer "emacs.scm<gnu>")
      (goto-char (point-max))
      (delete-blank-lines)
      (insert "\n")
      (yank)
      (save-buffer)
      (guix-commit package
                   (format "Add %s." package)
                   "New public variable."))
    (switch-to-buffer (get-buffer "*shell guix*"))
    (insert "env PAGER= git log --oneline --max-count=1")
    (comint-send-input)
    (insert "./pre-inst-env env GUIX_PACKAGE_PATH= guix build --no-grafts "
            package)
    (comint-send-input)))

(defun guix-commit-fix-linter ()
  (interactive)
  (save-buffer)
  (let ((var (save-excursion
               (geiser-syntax--pop-to-top)
               (forward-char)
               (forward-sexp)
               (forward-char)
               (thing-at-point 'symbol)))
        (filename (buffer-file-name)))
    (call-interactively #'vc-next-action)
    (call-interactively #'vc-next-action)
    (insert "wigust: " var ": Fix linter warning.")
    (call-interactively #'fill-paragraph)
    (newline 2)
    (insert (format "* %s (%s): Fix linter warning."
                    (f-relative filename
                                (f-expand (vc-git-root filename)))
                    var))
    (log-edit-done)))

;; (local-set-key (kbd "<f5>") (lambda () (interactive) (guix-mu-foo)))
;; (local-set-key (kbd "<f5>") (lambda () (interactive) (switch-to-buffer "*Shell Command Output*")))

;; git -C /home/natsu/src/guix-wigust reset --hard HEAD~ && git reset --hard HEAD~

;; (defhydra hydra-guix-mu () "merge upstream"
;;   ("C" guix-mu-copy-and-commit "copy and commit")
;;   ("N" guix-mu-other-next "other next")
;;   ("P" guix-mu-other-prev "other prev")
;;   ("Y" guix-mu-copy "copy")
;;   ("c" guix-mu-commit "commit")
;;   ("k" guix-mu-kill-sexp "kill-sexp")
;;   ("n" guix-mu-next "next")
;;   ("o" guix-mu-other "other")
;;   ("p" guix-mu-prev "prev")
;;   ("q" nil "quit")
;;   ("r" guix-mu-revert "revert")
;;   ("u" undo "undo")
;;   ("y" guix-mu-yank "yank"))

;; (global-set-key (kbd "<f5>") #'hydra-guix-mu/body)

(provide 'guix-merge-upstream)
;;; guix-merge-upstream.el ends here