summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/emacs/modules/mm-humanwave.el9
-rw-r--r--.config/emacs/modules/mm-projects.el44
-rw-r--r--.config/emacs/site-lisp/gh.el22
-rw-r--r--.config/emacs/site-lisp/marker.el47
4 files changed, 78 insertions, 44 deletions
diff --git a/.config/emacs/modules/mm-humanwave.el b/.config/emacs/modules/mm-humanwave.el
index 40bde27..3aa97b3 100644
--- a/.config/emacs/modules/mm-humanwave.el
+++ b/.config/emacs/modules/mm-humanwave.el
@@ -79,7 +79,6 @@ If METHOD is nil, a GET request is performed."
;;; Insert Imports in Vue
-
(defun mm-humanwave-insert-vue-import-path (base-directory target-file)
"Insert an import directive at POINT.
The import directive imports TARGET-FILE relative from BASE-DIRECTORY.
@@ -95,8 +94,15 @@ behaviour of the INCLUDE-ALL-P argument to `mm-project-read-file-name'."
(mm-humanwave-project-read-file-name current-prefix-arg)))
(let ((path (file-name-sans-extension
(file-relative-name target-file base-directory))))
+ (unless (string-match-p "/" path)
+ (setq path (concat "./" path)))
(insert "import ")
(save-excursion
+ (insert (thread-last
+ (file-name-base path)
+ (mm-string-split "-")
+ (mapconcat #'capitalize)))
+ (push-mark (point))
(insert (format " from '%s';" path)))))
(defun mm-humanwave-project-read-file-name (&optional include-all-p)
@@ -132,5 +138,4 @@ to the `project-find-file' command."
(message "%s" path)
path))))
-
(provide 'mm-humanwave)
diff --git a/.config/emacs/modules/mm-projects.el b/.config/emacs/modules/mm-projects.el
index 25c1a18..02d7af4 100644
--- a/.config/emacs/modules/mm-projects.el
+++ b/.config/emacs/modules/mm-projects.el
@@ -108,45 +108,7 @@ This is intended to be called interactively via
;;; GitHub Pull Requests
(require 'gh)
-(keymap-global-set "C-c p" #'gh-create-pr)
+(keymap-global-set "C-c p c" #'gh-create-pr)
+(keymap-global-set "C-c p o" #'gh-open-previous-pr)
-;; (defun mm-gh--get-labels ()
-;; (with-temp-buffer
-;; (call-process "gh" nil t nil "label" "list" "--json" "name")
-;; (goto-char (point-min))
-;; (let* ((data (json-parse-buffer))
-;; (labels (seq-map (lambda (x) (gethash "name" x)) data)))
-;; (sort labels
-;; :in-place t
-;; :lessp (lambda (x y)
-;; (let ((prefix-x-p (string-prefix-p "Sprint " x))
-;; (prefix-y-p (string-prefix-p "Sprint " y)))
-;; (cond
-;; ((and prefix-x-p prefix-y-p) (string> x y))
-;; (prefix-x-p t)
-;; (prefix-y-p nil)
-;; (:else (string< x y)))))))))
-
-;; (defun mm-gh-create-pr (title draftp labels)
-;; "Create a GitHub pull request using the gh CLI.
-;; If DRAFT is non-nil, the PR will be created as a draft.
-;; LABELS should be a comma-separated string of GitHub labels."
-;; (interactive
-;; (list
-;; (read-string (format-prompt "PR Title" nil))
-;; (y-or-n-p "Create as draft PR? ")
-;; (completing-read-multiple (format-prompt "PR Labels" nil)
-;; (mm-gh--get-labels))))
-;; (let* ((branch (car (vc-git-branches)))
-;; (title (format "%s %s" branch title))
-;; (flags `("--fill-verbose" "--title" ,title "--assignee" "@me"))
-;; (label-string (mapconcat #'identity labels ",")))
-;; (when draftp
-;; (setq flags (append flags '("--draft"))))
-;; (when labels
-;; (setq flags (append flags `("--label" ,label-string))))
-;; (with-temp-buffer
-;; (apply #'call-process "gh" nil t nil "pr" "create" flags)
-;; (message (buffer-string)))))
-
-(provide 'mm-projects) \ No newline at end of file
+(provide 'mm-projects)
diff --git a/.config/emacs/site-lisp/gh.el b/.config/emacs/site-lisp/gh.el
index 0461b18..23086e5 100644
--- a/.config/emacs/site-lisp/gh.el
+++ b/.config/emacs/site-lisp/gh.el
@@ -36,4 +36,24 @@ via `gh-get-labels'."
(apply #'call-process "gh" nil t nil "pr" "create" flags)
(message (buffer-string)))))
-(provide 'gh) \ No newline at end of file
+(defvar gh-pr-regexp
+ "\\`https://\\(?:www\\.\\)?github\\.com/[^/]+/[^/]+/pull/[[:digit:]]+\\'")
+
+(defun gh--pr-link-p (s)
+ (declare (pure t) (side-effect-free t))
+ (string-match-p gh-pr-regexp s))
+
+(defun gh-open-previous-pr ()
+ "Open the previous GitHub pull request.
+Opens the previous pull request created by `gh-create-pr' by searching
+for the echoed URL in the `*Messages*' buffer."
+ (interactive)
+ (with-current-buffer "*Messages*"
+ (goto-char (point-max))
+ (while (not (gh--pr-link-p (buffer-substring-no-properties
+ (pos-bol) (pos-eol))))
+ (unless (line-move -1 :noerror)
+ (user-error "No previous pull request found.")))
+ (browse-url-at-point)))
+
+(provide 'gh)
diff --git a/.config/emacs/site-lisp/marker.el b/.config/emacs/site-lisp/marker.el
new file mode 100644
index 0000000..f39cad4
--- /dev/null
+++ b/.config/emacs/site-lisp/marker.el
@@ -0,0 +1,47 @@
+(require 'hi-lock)
+(require 'seq)
+
+(defun marker-mark ()
+ (interactive)
+ (marker-mark-region (if (use-region-p)
+ (region-bounds)
+ `((,(pos-bol) . ,(pos-eol)))))
+ (when (region-active-p)
+ (deactivate-mark)))
+
+(defun marker-mark-region (bounds)
+ (dolist (x bounds) (marker--mark-region (car x) (cdr x))))
+
+(defun marker--mark-region (beg end)
+ (let ((ov (make-overlay beg end nil :front-advance)))
+ (overlay-put ov 'priority 1)
+ (overlay-put ov 'face 'hi-yellow)
+ (overlay-put ov 'evaporate t)
+ (overlay-put ov 'marker--mark-p t)))
+
+(defun marker-unmark ()
+ (interactive)
+ (if (use-region-p)
+ (marker-unmark-region (region-bounds))
+ (marker-clear))
+ (when (region-active-p)
+ (deactivate-mark)))
+
+(defun marker-unmark-region (bounds)
+ (dolist (x bounds) (marker--unmark-region (car x) (cdr x))))
+
+(defun marker--unmark-region (beg end)
+ (dolist (ov (seq-filter (lambda (ov) (overlay-get ov 'marker--mark-p))
+ (overlays-in beg end)))
+ (cond ((< (overlay-start ov) beg)
+ (move-overlay ov (overlay-start ov) beg))
+ ((> (overlay-end ov) end)
+ (move-overlay ov end (overlay-end ov)))
+ (:else
+ (delete-overlay ov)))))
+
+(defun marker-clear ()
+ (interactive)
+ (remove-overlays nil nil 'marker--mark-p t))
+
+(provide 'marker)