poly-ein--record-window-buffer

`C-x b` should take me back to base notebook buffer, if not indirect buffer.
This commit is contained in:
dickmao 2020-02-15 14:29:00 -05:00
parent a3604a329a
commit ec67737883
2 changed files with 38 additions and 16 deletions

View file

@ -1161,7 +1161,10 @@ Tried add-function: the &rest from :around is an emacs-25 compilation issue."
`(if (functionp (quote ,defn)) `(if (functionp (quote ,defn))
(progn (progn
(fset (quote ,km) (lambda () (interactive) (fset (quote ,km) (lambda () (interactive)
(poly-ein-base (call-interactively (function ,defn))))) (condition-case err
(poly-ein-base (call-interactively (function ,defn)))
(cl-no-method (message "%s: no applicable method" (quote ,km)))
(error (message "%s: %s" (quote ,km) (error-message-string err))))))
(define-key ,keymap ,key (quote ,km))) (define-key ,keymap ,key (quote ,km)))
(define-key ,keymap ,key (quote ,defn))))) (define-key ,keymap ,key (quote ,defn)))))

View file

@ -139,11 +139,9 @@
(pm-allow-post-command-hook nil) (pm-allow-post-command-hook nil)
(pm-initialization-in-progress t)) (pm-initialization-in-progress t))
(poly-ein--set-buffer derived-buffer base-buffer) (poly-ein--set-buffer derived-buffer base-buffer)
(condition-case err (unwind-protect
(prog1 (progn ,@body) (progn ,@body)
(poly-ein--set-buffer base-buffer derived-buffer)) (poly-ein--set-buffer base-buffer derived-buffer))))
(error (message "%s" (error-message-string err))
(poly-ein--set-buffer base-buffer derived-buffer)))))
(defclass pm-inner-overlay-chunkmode (pm-inner-auto-chunkmode) (defclass pm-inner-overlay-chunkmode (pm-inner-auto-chunkmode)
() ()
@ -155,10 +153,9 @@
TYPE can be 'body, nil." TYPE can be 'body, nil."
(poly-ein-base (poly-ein-base
(setq pos (or pos (point))) (setq pos (or pos (point)))
;; Assume: ein:worksheet-get-current-cell always returns non-nil (when-let ((result-cm cm)
(let ((result-cm cm) (span `(nil ,(point-min) ,(point-min)))
(span `(nil ,(point-min) ,(point-min))) (cell (ein:worksheet-get-current-cell :pos pos :noerror t)))
(cell (ein:worksheet-get-current-cell :pos pos :noerror nil)))
;; Change :mode if necessary ;; Change :mode if necessary
(-when-let* ((lang (-when-let* ((lang
(condition-case err (condition-case err
@ -185,12 +182,12 @@ TYPE can be 'body, nil."
(ein:display-warning warning)))) (ein:display-warning warning))))
(setq result-cm (setq result-cm
(cl-loop for ocm in (eieio-oref pm/polymode '-auto-innermodes) (cl-loop for ocm in (eieio-oref pm/polymode '-auto-innermodes)
when (equal mode (ein:oref-safe ocm 'mode)) when (equal mode (ein:oref-safe ocm 'mode))
return ocm return ocm
finally return (let ((new-mode (clone cm :mode mode))) finally return (let ((new-mode (clone cm :mode mode)))
(object-add-to-list pm/polymode '-auto-innermodes (object-add-to-list pm/polymode '-auto-innermodes
new-mode) new-mode)
new-mode)))) new-mode))))
;; Span is a zebra pattern of "body" (within input cell) and "nil" ;; Span is a zebra pattern of "body" (within input cell) and "nil"
;; (outside input cell). Decide boundaries of span and return it. ;; (outside input cell). Decide boundaries of span and return it.
(let ((rel (poly-ein--relative-to-input pos cell))) (let ((rel (poly-ein--relative-to-input pos cell)))
@ -257,6 +254,27 @@ TYPE can be 'body, nil."
(add-function :around (local 'font-lock-syntactic-face-function) (add-function :around (local 'font-lock-syntactic-face-function)
(apply-partially #'poly-ein--narrow-to-inner #'identity)))) (apply-partially #'poly-ein--narrow-to-inner #'identity))))
(defun poly-ein--record-window-buffer ()
"(pm--visible-buffer-name) needs to get onto window's prev-buffers.
But `C-x b` seems to consult `buffer-list' and not the C (window)->prev_buffers."
(when (buffer-base-buffer)
(let* ((buffer-list (frame-parameter nil 'buffer-list))
(pos-visible (seq-position
buffer-list
(pm--visible-buffer-name)
(lambda (x visible*)
(string-prefix-p (buffer-name x) visible*)))))
;; no way to know if i've switched in or out of indirect buf.
;; (if in, I *don't* want to add visible to buffer-list)
(cond ((and (numberp pos-visible) (> pos-visible 0))
(let ((visible-buffer (nth pos-visible buffer-list)))
(setcdr (nthcdr (1- pos-visible) buffer-list)
(nthcdr (1+ pos-visible) buffer-list))
(set-frame-parameter nil 'buffer-list (cons visible-buffer buffer-list))))
((null pos-visible)
(set-frame-parameter nil 'buffer-list
(cons (buffer-base-buffer) buffer-list)))))))
(defun poly-ein-init-input-cell (_type) (defun poly-ein-init-input-cell (_type)
"Contrary to intuition, this inits the entire buffer of input cells "Contrary to intuition, this inits the entire buffer of input cells
(collectively denoted by the chunkmode pm-inner/ein-input-cell), not each individual one." (collectively denoted by the chunkmode pm-inner/ein-input-cell), not each individual one."
@ -265,6 +283,7 @@ TYPE can be 'body, nil."
(poly-ein-copy-state (pm-base-buffer) (current-buffer)) (poly-ein-copy-state (pm-base-buffer) (current-buffer))
(setq-local font-lock-dont-widen t) (setq-local font-lock-dont-widen t)
(setq-local syntax-propertize-chunks 0) ;; internal--syntax-propertize too far (setq-local syntax-propertize-chunks 0) ;; internal--syntax-propertize too far
(add-hook 'buffer-list-update-hook #'poly-ein--record-window-buffer nil t)
(ein:notebook-mode)) (ein:notebook-mode))
(defcustom pm-host/ein (defcustom pm-host/ein