blob: 7d805433c026348bb8d3a57c7a4f0dff2ea2b3e0 (
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
|
;;; km-util.el --- Utilities
;; Copyright Kyle Meyer <kyle@kyleam.com>
;; Author: Kyle Meyer <kyle@kyleam.com>
;; URL: https://git.kyleam.com/emacs.d
;; 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/>.
;;; Code:
(require 'seq)
(defun km/mode-buffers (mode)
(seq-filter (lambda (buf)
(with-current-buffer buf
(derived-mode-p mode)))
(buffer-list)))
(defun km/region-or-buffer-line-bounds ()
"Return line bounds for region.
If region is active, return postions that mark the beginning of
the first line and end of the last line that the region touches.
If there is no active region, return a the minimum and maximum
point in the buffer."
(if (use-region-p)
(let ((beg (region-beginning))
(end (region-end)))
(save-excursion
(list (progn (goto-char beg) (point-at-bol))
(progn (goto-char end) (1+ (point-at-eol))))))
(list (point-min) (point-max))))
(defun km/open-github-patch (buffer)
"Find GitHub patch link in BUFFER and show it in a new buffer."
(let ((url
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(if (re-search-forward "https://github\\.com/.*\\.patch" nil t)
(match-string-no-properties 0)
(user-error "No patch found"))))))
(with-current-buffer (get-buffer-create
(generate-new-buffer-name "*mail-github-patch*"))
(url-insert-file-contents url)
(diff-mode)
(view-mode 1)
(pop-to-buffer (current-buffer)))))
(provide 'km-util)
;;; km-util.el ends here
|