aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/window.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/window.el')
-rw-r--r--lisp/window.el72
1 files changed, 72 insertions, 0 deletions
diff --git a/lisp/window.el b/lisp/window.el
index 46de1819c69..3867f6fa6ef 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -10838,6 +10838,78 @@ displaying that processes's buffer."
10838 (set-process-window-size process (cdr size) (car size)))))))))) 10838 (set-process-window-size process (cdr size) (car size))))))))))
10839 10839
10840(add-hook 'window-configuration-change-hook 'window--adjust-process-windows) 10840(add-hook 'window-configuration-change-hook 'window--adjust-process-windows)
10841
10842
10843;;; Window point context
10844
10845(defun window-point-context-set ()
10846 "Set context near the window point.
10847Call function specified by `window-point-context-set-function' for every
10848live window on the selected frame with that window as sole argument.
10849The function called is supposed to return a context of the window's point
10850that can be later used as argument for `window-point-context-use-function'.
10851Remember the returned context in the window parameter `context'."
10852 (walk-windows
10853 (lambda (w)
10854 (when-let ((fn (buffer-local-value 'window-point-context-set-function
10855 (window-buffer w)))
10856 ((functionp fn))
10857 (context (funcall fn w)))
10858 (set-window-parameter w 'context (cons (buffer-name) context))))
10859 'nomini))
10860
10861(defun window-point-context-use ()
10862 "Use context to relocate the window point.
10863Call function specified by `window-point-context-use-function' to move the
10864window point according to the previously saved context. For every live
10865window on the selected frame this function is called with two arguments:
10866the window and the context data structure saved by
10867`window-point-context-set-function' in the window parameter `context'.
10868The function called is supposed to set the window point to the location
10869found by the provided context."
10870 (walk-windows
10871 (lambda (w)
10872 (when-let ((fn (buffer-local-value 'window-point-context-use-function
10873 (window-buffer w)))
10874 ((functionp fn))
10875 (context (window-parameter w 'context))
10876 ((equal (buffer-name) (car context))))
10877 (funcall fn w (cdr context))
10878 (set-window-parameter w 'context nil)))
10879 'nomini))
10880
10881(add-to-list 'window-persistent-parameters '(context . writable))
10882
10883(defun window-point-context-set-default-function (w)
10884 "Set context of file buffers to the front and rear strings."
10885 (with-current-buffer (window-buffer w)
10886 (when buffer-file-name
10887 (let ((point (window-point w)))
10888 `((front-context-string
10889 . ,(buffer-substring-no-properties
10890 point (min (+ point 16) (point-max))))
10891 (rear-context-string
10892 . ,(buffer-substring-no-properties
10893 point (max (- point 16) (point-min)))))))))
10894
10895(defun window-point-context-use-default-function (w context)
10896 "Restore context of file buffers by the front and rear strings."
10897 (with-current-buffer (window-buffer w)
10898 (let ((point (window-point w)))
10899 (save-excursion
10900 (goto-char point)
10901 (when-let ((f (alist-get 'front-context-string context))
10902 ((search-forward f (point-max) t)))
10903 (goto-char (match-beginning 0))
10904 (when-let ((r (alist-get 'rear-context-string context))
10905 ((search-backward r (point-min) t)))
10906 (goto-char (match-end 0))
10907 (setq point (point)))))
10908 (set-window-point w point))))
10909
10910(defvar window-point-context-set-function 'window-point-context-set-default-function)
10911(defvar window-point-context-use-function 'window-point-context-use-default-function)
10912
10841 10913
10842;; Some of these are in tutorial--default-keys, so update that if you 10914;; Some of these are in tutorial--default-keys, so update that if you
10843;; change these. 10915;; change these.