help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When do you prefer frames instead of windows?


From: Yuri Khan
Subject: Re: When do you prefer frames instead of windows?
Date: Wed, 26 Nov 2014 12:02:15 +0700

On Tue, Nov 25, 2014 at 9:57 PM, Ralf Fassel <address@hidden> wrote:

> I now have bound a key to get my ediff control panel back:
>     <C-M-up> runs the command (lambda nil (interactive) (let ((buf
>     (get-buffer "*Ediff Control Panel*"))) (if buf (pop-to-buffer buf)))),
>     which is an interactive Lisp function.
> and then C-l recenters everything (could even pack that in the
> keybinding, but...)

You might want to go further (I know I do!) and make bindings that (1)
temporarily switch to the ediff control panel, (2) perform an ediff
control panel command, (3) switch back to the buffer you were in ā€” for
each command that you frequently use in ediff. (Personally I find
next-difference and previous-difference sufficient.)

Something like this:

(require 'cl)

(defun yk-global-ediff--find-session (buffer)
  "Return the control buffer of the first ediff session involving
BUFFER, or the control buffer of the first ediff session, or nil."
  (or (cl-find-if (lambda (control-buffer)
                    (with-current-buffer control-buffer
                      (memq buffer (list ediff-buffer-A ediff-buffer-B
ediff-buffer-C))))
                  ediff-session-registry)
      (car-safe ediff-session-registry)))

(defun yk-global-ediff-next-difference ()
  "Go to the next difference according to the ediff session involving
the current buffer, or if there is no such session, according to the
first ediff session."
  (interactive)
  (let ((session (yk-global-ediff--find-session (current-buffer))))
    (when session
      (save-window-excursion
        (with-current-buffer session
          (ediff-next-difference))))))

(defun yk-global-ediff-previous-difference ()
  "Go to the previous difference according to the ediff session
involving the current buffer, or if there is no such session, according
to the first ediff session."
  (interactive)
  (let ((session (yk-global-ediff--find-session (current-buffer))))
    (when session
      (save-window-excursion
        (with-current-buffer session
          (ediff-previous-difference))))))

(define-minor-mode yk-global-ediff-navigation-mode
  "Toggle global ediff navigation mode."
  :global t
  :lighter " Eā‰œ"
  :init-value nil
  :keymap `((,(kbd "M-n") . yk-global-ediff-next-difference)
            (,(kbd "M-p") . yk-global-ediff-previous-difference)))

(defun yk-global-ediff--cleanup ()
  (unless ediff-session-registry
    (yk-global-ediff-navigation-mode 0)))

(add-hook 'ediff-mode-hook 'yk-global-ediff-navigation-mode)
(add-hook 'ediff-cleanup-hook 'yk-global-ediff--cleanup)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]