branch: master commit 9029356ed0b33f4b50f3ae7d5f327fe487008859 Author: Mitchel Humpherys <mitch.spec...@gmail.com> Commit: Mitchel Humpherys <mitch.spec...@gmail.com>
Update documentation --- Makefile | 8 ++++++++ README.md | 40 ++++++++++++++++++++++++++++++++-------- diffview.el | 47 ++++++++++++++++++++++++----------------------- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d2403cf --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +README.md: make-readme-markdown.el diffview.el + emacs --script $< < diffview.el >$@ 2>/dev/null + +make-readme-markdown.el: + wget -q -O $@ https://raw.github.com/mgalgs/make-readme-markdown/master/make-readme-markdown.el + +.INTERMEDIATE: make-readme-markdown.el +.PHONY: README.md diff --git a/README.md b/README.md index 11807e5..59fc3a2 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,58 @@ -Commentary -========== +## diffview.el +*View diffs in side-by-side format* + +--- +[](http://www.gnu.org/licenses/gpl-3.0.html) Take a plain ol' diff and view it in an easier-to-comprehend side-by-side format. This comes in handy for ready patches from mailing lists (or from whencever you might acquire them). -Installation -============ +### Installation + Put this file on your load-path and do: (require 'diffview) -Use -=== +### Usage + The following functions are provided: * `diffview-current` : Opens the current buffer with `diffview` * `diffview-region` : Opens the current region with `diffview` +* `diffview-message` : Opens the current email message with `diffview` -Screenshots -=========== +### Screenshots + Before:<br> <img src="https://raw.github.com/mgalgs/diffview-mode/master/screenshots/diffview-before.png"><br> After:<br> <img src="https://raw.github.com/mgalgs/diffview-mode/master/screenshots/diffview-after.png"><br> +### Function Documentation + + +#### `(diffview-current)` + +Parses the content of the current buffer as a diff and opens + the result in a side-by-side view + +#### `(diffview-region)` + +Parses the content of the current buffer as a diff and opens + the result in a side-by-side view + +#### `(diffview-message)` + +Parses the content of the current buffer (assumed to be a + message (i.e. in `Article` mode)) as a diff and opens the + result in a side-by-side view + +----- <div style="padding-top:15px;color: #d0d0d0;"> Markdown README file generated by <a href="https://github.com/mgalgs/make-readme-markdown">make-readme-markdown.el</a> diff --git a/diffview.el b/diffview.el index 88ed98d..45e421f 100644 --- a/diffview.el +++ b/diffview.el @@ -53,7 +53,7 @@ (require 'message) -(defun diffview/print-all-lines-to-buffer (lines buffer-name) +(defun diffview--print-all-lines-to-buffer (lines buffer-name) "Prints each line in `LINES' to a buffer named `BUFFER-NAME' with an intervening \n between each line" (let ((old-temp-buffer (get-buffer buffer-name))) @@ -65,18 +65,18 @@ (dolist (line lines) (insert line "\n"))))) -(defvar diffview/minus-bufname "*side-by-side-1*") -(defvar diffview/plus-bufname "*side-by-side-2*") -(defvar diffview/saved-wincfg nil) -(defvar diffview/regexp-is-plus-line "^\\+\\([^+]\\{1\\}\\|$\\)" +(defvar diffview--minus-bufname "*side-by-side-1*") +(defvar diffview--plus-bufname "*side-by-side-2*") +(defvar diffview--saved-wincfg nil) +(defvar diffview--regexp-is-plus-line "^\\+\\([^+]\\{1\\}\\|$\\)" "a + followed by one non + or the end of the line") -(defvar diffview/regexp-is-minus-line "^-\\([^-]\\{1\\}\\|$\\)" +(defvar diffview--regexp-is-minus-line "^-\\([^-]\\{1\\}\\|$\\)" "a - followed by one non - or the end of the line") -(defun diffview/view-string (input-string) +(defun diffview--view-string (input-string) "Parses `INPUT-STRING' as a diff and opens the result in a side-by-side view" - (setq diffview/saved-wincfg (current-window-configuration)) + (setq diffview--saved-wincfg (current-window-configuration)) (delete-other-windows) (let (plus-lines minus-lines @@ -89,11 +89,11 @@ side-by-side view" (all-lines (split-string input-string "\n"))) (dolist (line all-lines) (cond - ((string-match diffview/regexp-is-plus-line line) + ((string-match diffview--regexp-is-plus-line line) (push line plus-lines) (setq current-state 'in-plus) (setq current-lines-in-plus (1+ current-lines-in-plus))) - ((string-match diffview/regexp-is-minus-line line) + ((string-match diffview--regexp-is-minus-line line) (push line minus-lines) (setq current-state 'in-minus) (setq current-lines-in-minus (1+ current-lines-in-minus))) @@ -132,17 +132,17 @@ side-by-side view" (setq last-state current-state)) - (diffview/print-all-lines-to-buffer (reverse minus-lines) diffview/minus-bufname) - (diffview/print-all-lines-to-buffer (reverse plus-lines) diffview/plus-bufname) + (diffview--print-all-lines-to-buffer (reverse minus-lines) diffview--minus-bufname) + (diffview--print-all-lines-to-buffer (reverse plus-lines) diffview--plus-bufname) - (switch-to-buffer diffview/minus-bufname nil t) + (switch-to-buffer diffview--minus-bufname nil t) (goto-char (point-min)) (diffview-mode) (split-window-right) (other-window 1) - (switch-to-buffer diffview/plus-bufname nil t) + (switch-to-buffer diffview--plus-bufname nil t) (goto-char (point-min)) (diffview-mode) @@ -153,14 +153,14 @@ side-by-side view" "Parses the content of the current buffer as a diff and opens the result in a side-by-side view" (interactive) - (diffview/view-string (buffer-string))) + (diffview--view-string (buffer-string))) ;;;###autoload (defun diffview-region () "Parses the content of the current buffer as a diff and opens the result in a side-by-side view" (interactive) - (diffview/view-string (buffer-substring (point) (mark)))) + (diffview--view-string (buffer-substring (point) (mark)))) ;;;###autoload (defun diffview-message () @@ -175,28 +175,29 @@ side-by-side view" (setq beg (1+ (point))) (search-forward-regexp "^-- $") (setq end (1+ (point))) - (diffview/view-string (buffer-substring beg end))))) + (diffview--view-string (buffer-substring beg end))))) -;;; diffview-mode ;;; +;;; You probably don't want to invoke `diffview-mode' directly. Just use +;;; one of the autoload functions above. (define-derived-mode diffview-mode special-mode "Diffview" "Mode for viewing diffs side-by-side" (setq font-lock-defaults '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil)))) -(defun diffview/quit () +(defun diffview--quit () "Quit diffview and clean up diffview buffers" (interactive) (delete-other-windows) (scroll-all-mode 0) - (let ((plusbuf (get-buffer diffview/plus-bufname)) - (minusbuf (get-buffer diffview/minus-bufname))) + (let ((plusbuf (get-buffer diffview--plus-bufname)) + (minusbuf (get-buffer diffview--minus-bufname))) (if plusbuf (kill-buffer plusbuf)) (if minusbuf (kill-buffer minusbuf))) - (set-window-configuration diffview/saved-wincfg)) + (set-window-configuration diffview--saved-wincfg)) -(define-key diffview-mode-map (kbd "q") 'diffview/quit) +(define-key diffview-mode-map (kbd "q") 'diffview--quit) (provide 'diffview) ;;; diffview.el ends here