From: "David Kågedal" <davidk@lysator.liu.se>
To: catalin.marinas@gmail.com, git@vger.kernel.org
Subject: [StGit PATCH 01/17] Add an StGit mode for emacs
Date: Fri, 14 Dec 2007 11:55:42 +0100 [thread overview]
Message-ID: <20071214105530.18066.14326.stgit@krank> (raw)
In-Reply-To: <20071214105238.18066.23281.stgit@krank>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
contrib/stgit.el | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 141 insertions(+), 0 deletions(-)
create mode 100644 contrib/stgit.el
diff --git a/contrib/stgit.el b/contrib/stgit.el
new file mode 100644
index 0000000..1bdc0a5
--- /dev/null
+++ b/contrib/stgit.el
@@ -0,0 +1,141 @@
+(defun stgit (dir)
+ "Manage stgit patches"
+ (interactive "DDirectory: \n")
+ (switch-to-stgit-buffer dir)
+ (stgit-refresh))
+
+(defun switch-to-stgit-buffer (dir)
+ "Switch to a (possibly new) buffer displaying StGit patches for DIR"
+ (setq dir (file-name-as-directory dir))
+ (let ((buffers (buffer-list)))
+ (while (and buffers
+ (not (with-current-buffer (car buffers)
+ (and (eq major-mode 'stgit-mode)
+ (string= default-directory dir)))))
+ (setq buffers (cdr buffers)))
+ (switch-to-buffer (if buffers
+ (car buffers)
+ (create-stgit-buffer dir)))))
+
+(defun create-stgit-buffer (dir)
+ "Create a buffer for showing StGit patches.
+Argument DIR is the repository path."
+ (let ((buf (create-file-buffer (concat dir "*stgit*")))
+ (inhibit-read-only t))
+ (with-current-buffer buf
+ (setq default-directory dir)
+ (stgit-mode)
+ (setq buffer-read-only t))
+ buf))
+
+(defmacro stgit-capture-output (name &rest body)
+ "Capture StGit output and show it in a window at the end"
+ `(let ((output-buf (get-buffer-create ,(or name "*StGit output*"))))
+ (with-current-buffer output-buf
+ (erase-buffer))
+ (let ((standard-output output-buf))
+ ,@body)
+ (if (with-current-buffer output-buf (< (point-min) (point-max)))
+ (display-buffer output-buf t))))
+(put 'stgit-capture-output 'lisp-indent-function 1)
+
+(defun stgit-run (&rest args)
+ (apply 'call-process "stg" nil standard-output nil args))
+
+(defun stgit-refresh ()
+ "Update the contents of the stgit buffer"
+ (interactive)
+ (let ((inhibit-read-only t)
+ (curline (line-number-at-pos))
+ (curpatch (stgit-patch-at-point)))
+ (erase-buffer)
+ (insert "Branch: ")
+ (stgit-run "branch")
+ (stgit-run "series")
+ (if curpatch
+ (stgit-goto-patch curpatch)
+ (goto-line curline))))
+
+(defvar stgit-mode-hook nil
+ "Run after `stgit-mode' is setup.")
+
+(defvar stgit-mode-map nil
+ "Keymap for StGit major mode.")
+
+(unless stgit-mode-map
+ (setq stgit-mode-map (make-keymap))
+ (suppress-keymap stgit-mode-map)
+ (define-key stgit-mode-map "g" 'stgit-refresh)
+ (define-key stgit-mode-map "r" 'stgit-rename)
+ (define-key stgit-mode-map ">" 'stgit-push-next)
+ (define-key stgit-mode-map "<" 'stgit-pop)
+ (define-key stgit-mode-map "=" 'stgit-show))
+
+(defun stgit-mode ()
+ "Major mode for interacting with StGit.
+Commands:
+\\{stgit-mode-map}"
+ (kill-all-local-variables)
+ (buffer-disable-undo)
+ (setq mode-name "StGit"
+ major-mode 'stgit-mode
+ goal-column 2)
+ (use-local-map stgit-mode-map)
+ (set (make-local-variable 'list-buffers-directory) default-directory)
+ (run-hooks 'stgit-mode-hook))
+
+(defun stgit-patch-at-point ()
+ "Return the patch name on the current line"
+ (save-excursion
+ (beginning-of-line)
+ (if (looking-at "[>+-] \\(.*\\)")
+ (match-string 1)
+ nil)))
+
+(defun stgit-goto-patch (patch)
+ "Move point to the line containing PATCH"
+ (let ((p (point)))
+ (goto-char (point-min))
+ (if (re-search-forward (concat "[>+-] " (regexp-quote patch) "$") nil t)
+ (progn (move-to-column goal-column)
+ t)
+ (goto-char p)
+ nil)))
+
+(defun stgit-rename (name)
+ "Rename the patch under point"
+ (interactive (list (read-string "Patch name: " (stgit-patch-at-point))))
+ (let ((old-name (stgit-patch-at-point)))
+ (unless old-name
+ (error "No patch on this line"))
+ (stgit-capture-output nil
+ (stgit-run "rename" old-name name))
+ (stgit-refresh)
+ (stgit-goto-patch name)))
+
+(defun stgit-push-next ()
+ "Push the patch on the line after pos"
+ (interactive)
+ (forward-line 1)
+ (let ((patch (stgit-patch-at-point)))
+ (stgit-capture-output nil
+ (stgit-run "push" patch))
+ (stgit-refresh)))
+
+(defun stgit-pop ()
+ "Pop the patch on the current line"
+ (interactive)
+ (let ((patch (stgit-patch-at-point)))
+ (stgit-capture-output nil
+ (stgit-run "pop" patch))
+ (stgit-refresh)
+ (previous-line)))
+
+(defun stgit-show ()
+ "Show the patch on the current line"
+ (interactive)
+ (stgit-capture-output "*StGit patch*"
+ (stgit-run "show" (stgit-patch-at-point))
+ (with-current-buffer standard-output
+ (goto-char (point-min))
+ (diff-mode))))
next prev parent reply other threads:[~2007-12-14 10:55 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-14 10:55 [StGit PATCH 00/17] Series short description David Kågedal
2007-12-14 10:55 ` David Kågedal [this message]
2007-12-14 10:56 ` [StGit PATCH 02/17] Emacs mode: Show keybindings when user presses "h" or "?" David Kågedal
2007-12-14 10:56 ` [StGit PATCH 03/17] Emacs mode: Add an explanatory header David Kågedal
2007-12-14 10:57 ` [StGit PATCH 04/17] Emacs mode: Makefile for building stgit.el David Kågedal
2007-12-14 10:57 ` [StGit PATCH 05/17] Emacs mode: push/pop next patch, not patch at point David Kågedal
2007-12-14 10:57 ` [StGit PATCH 06/17] Emacs mode: Let "P" push or pop " David Kågedal
2007-12-14 10:57 ` [StGit PATCH 07/17] Emacs mode: Bind "G" to "stg goto" David Kågedal
2007-12-14 10:57 ` [StGit PATCH 08/17] Emacs mode: show patches' short description David Kågedal
2007-12-14 10:58 ` [StGit PATCH 09/17] Emacs mode: Improve the output buffer state David Kågedal
2007-12-14 10:58 ` [StGit PATCH 10/17] Emacs mode: Bind n and p David Kågedal
2007-12-14 10:58 ` [StGit PATCH 11/17] Emacs mode: add stgit-repair David Kågedal
2007-12-14 10:58 ` [StGit PATCH 12/17] Emacs mode: added stgit-commit and stgit-uncommit David Kågedal
2007-12-14 10:59 ` [StGit PATCH 13/17] Emacs mode: Add stgit-edit command David Kågedal
2007-12-14 10:59 ` [StGit PATCH 14/17] Emacs mode: added fontification David Kågedal
2007-12-14 10:59 ` [StGit PATCH 15/17] Emacs mode: Added stgit-new David Kågedal
2007-12-14 10:59 ` [StGit PATCH 16/17] Emacs mode: Add mark command David Kågedal
2007-12-14 10:59 ` [StGit PATCH 17/17] Emacs mode: coalesce command David Kågedal
2007-12-17 11:09 ` [StGit PATCH 00/17] Series short description Catalin Marinas
2007-12-17 22:48 ` Karl Hasselström
2007-12-18 5:21 ` kha/safe and kha/experimental updated Karl Hasselström
2007-12-18 16:09 ` Catalin Marinas
2007-12-18 16:39 ` Jakub Narebski
2007-12-18 16:52 ` Catalin Marinas
2007-12-19 9:41 ` David Kågedal
2007-12-19 9:50 ` David Kågedal
2007-12-19 10:19 ` Catalin Marinas
2007-12-19 9:38 ` Karl Hasselström
2007-12-19 10:44 ` Jakub Narebski
2007-12-19 11:40 ` Karl Hasselström
2007-12-19 11:47 ` Catalin Marinas
2007-12-19 16:23 ` Jakub Narebski
2007-12-19 17:02 ` Catalin Marinas
2007-12-19 17:14 ` David Kågedal
2007-12-19 17:14 ` Karl Hasselström
2007-12-19 9:34 ` Karl Hasselström
2007-12-19 10:09 ` Catalin Marinas
2007-12-19 11:20 ` Karl Hasselström
2007-12-19 11:40 ` Catalin Marinas
2007-12-19 12:10 ` Karl Hasselström
2007-12-19 15:38 ` Catalin Marinas
2007-12-19 14:59 ` Catalin Marinas
2007-12-19 15:39 ` David Kågedal
2007-12-18 9:11 ` [StGit PATCH 00/17] Series short description Catalin Marinas
2007-12-18 9:20 ` David Kågedal
2007-12-18 9:24 ` Karl Hasselström
2007-12-19 22:19 ` [StGit PATCH 0/2] Make new infrastructure subdirectory safe Karl Hasselström
2007-12-19 22:19 ` [StGit PATCH 1/2] Test that "stg goto" can be called from a subdirectory Karl Hasselström
2007-12-19 22:24 ` [StGit PATCH 2/2] Make "stg goto" subdirectory safe Karl Hasselström
2007-12-19 22:46 ` kha/safe updated Karl Hasselström
2007-12-19 23:17 ` Catalin Marinas
2007-12-19 23:26 ` Karl Hasselström
2007-12-19 23:29 ` Catalin Marinas
2007-12-20 6:39 ` Karl Hasselström
2007-12-19 23:24 ` David Kågedal
2007-12-20 6:38 ` Karl Hasselström
2007-12-19 22:28 ` [StGit PATCH 0/2] Make new infrastructure subdirectory safe Karl Hasselström
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071214105530.18066.14326.stgit@krank \
--to=davidk@lysator.liu.se \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).