Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak ediff to optionally ignore regions with magic comment. #2080

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/templates/.spacemacs.template
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ before layers configuration."
dotspacemacs-default-package-repository nil
)
;; User initialization goes here
;; EDIFF-IGNORE
)

(defun dotspacemacs/config ()
"Configuration function.
This function is called at the very end of Spacemacs initialization after
layers configuration."
;; EDIFF-IGNORE
)

;; Do not write anything past this comment. This is where Emacs will
;; auto-generate custom variable definitions.
;; EDIFF-IGNORE
53 changes: 51 additions & 2 deletions spacemacs/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,60 @@ argument takes the kindows rotate backwards."
(interactive)
(find-file-existing (dotspacemacs/location)))

(defun ediff-hide-regex-and-ignores (n)
"Tweaked version of `ediff-hide-regexp-matches'. This version
automatically matches regions that have the string
\"EDIFF-IGNORE\" in them. It also searches the line just above
the region."
(if (ediff-valid-difference-p n)
(let* ((ctl-buf ediff-control-buffer)
(ignore-regexp "EDIFF-IGNORE")
(regex-A ediff-regexp-hide-A)
(regex-B ediff-regexp-hide-B)
(regex-C ediff-regexp-hide-C)
(reg-A-match (ediff-with-current-buffer ediff-buffer-A
(save-restriction
(goto-char (ediff-get-diff-posn 'A 'beg n ctl-buf))
(narrow-to-region
(line-beginning-position 0)
(ediff-get-diff-posn 'A 'end n ctl-buf))
(goto-char (point-min))
(or (re-search-forward ignore-regexp nil t)
(and (not (string-empty-p regex-A))
(re-search-forward regex-A nil t))))))
(reg-B-match (ediff-with-current-buffer ediff-buffer-B
(save-restriction
(goto-char (ediff-get-diff-posn 'B 'beg n ctl-buf))
(narrow-to-region
(line-beginning-position 0)
(ediff-get-diff-posn 'B 'end n ctl-buf))
(goto-char (point-min))
(or (re-search-forward ignore-regexp nil t)
(and (not (string-empty-p regex-B))
(re-search-forward regex-B nil t))))))
(reg-C-match (when ediff-3way-comparison-job
(ediff-with-current-buffer ediff-buffer-C
(save-restriction
(goto-char (ediff-get-diff-posn 'C 'beg n ctl-buf))
(narrow-to-region
(line-beginning-position 0)
(ediff-get-diff-posn 'C 'end n ctl-buf))
(goto-char (point-min))
(or (re-search-forward ignore-regexp nil t)
(and (not (string-empty-p regex-C))
(re-search-forward regex-C nil t))))))))
(eval (if ediff-3way-comparison-job
(list ediff-hide-regexp-connective
reg-A-match reg-B-match reg-C-match)
(list ediff-hide-regexp-connective reg-A-match reg-B-match)))
)))

(defun ediff-dotfile-and-template ()
"ediff the current `dotfile' with the template"
(interactive)
(ediff-files (dotspacemacs/location)
(concat dotspacemacs-template-directory ".spacemacs.template")))
(let ((ediff-start-with-ignores t))
(ediff-files (dotspacemacs/location)
(concat dotspacemacs-template-directory ".spacemacs.template"))))

(defun find-spacemacs-file ()
(interactive)
Expand Down
13 changes: 12 additions & 1 deletion spacemacs/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,18 @@
ediff-window-setup-function 'ediff-setup-windows-plain
;; emacs is evil and decrees that vertical shall henceforth be horizontal
ediff-split-window-function 'split-window-horizontally
ediff-merge-split-window-function 'split-window-horizontally))))
ediff-merge-split-window-function 'split-window-horizontally)
(defvar ediff-start-with-ignores nil
"If non-nil start ediff using ediff-hide-regex-and-ignores to select diff
regions to compare.")
(add-hook 'ediff-startup-hook
(lambda ()
(when ediff-start-with-ignores
(setq-local
ediff-hide-regexp-matches-function 'ediff-hide-regex-and-ignores)
(setq-local
ediff-skip-diff-region-function 'ediff-hide-regex-and-ignores)
(ediff-update-diffs)))))))

(defun spacemacs/init-eldoc ()
(use-package eldoc
Expand Down