@@ -46,6 +46,37 @@ self = stdenv.mkDerivation {
46
46
(mapc (lambda (arg)
47
47
(when (file-directory-p (concat arg "/lib/coq/${ coq-version } /user-contrib"))
48
48
(setenv "COQPATH" (concat (getenv "COQPATH") ":" arg "/lib/coq/${ coq-version } /user-contrib")))) '(${ stdenv . lib . concatStringsSep " " ( map ( pkg : "\" ${ pkg } \" " ) pkgs ) } ))
49
+ ; TODO Abstract this pattern from here and nixBufferBuilders.withPackages!
50
+ (defvar nixpkgs--coq-buffer-count 0)
51
+ (when (eq nixpkgs--coq-buffer-count 0)
52
+ (make-variable-buffer-local 'nixpkgs--is-nixpkgs-coq-buffer)
53
+ (defun nixpkgs--coq-inherit (buf)
54
+ (inherit-local-inherit-child buf)
55
+ (with-current-buffer buf
56
+ (setq nixpkgs--coq-buffer-count (1+ nixpkgs--coq-buffer-count))
57
+ (add-hook 'kill-buffer-hook 'nixpkgs--decrement-coq-buffer-count nil t))
58
+ buf)
59
+ ; When generating a scomint buffer, do inherit-local inheritance and make it a nixpkgs-coq buffer
60
+ (defun nixpkgs--around-scomint-make (orig &rest r)
61
+ (if nixpkgs--is-nixpkgs-coq-buffer
62
+ (progn
63
+ (advice-add 'get-buffer-create :filter-return #'nixpkgs--coq-inherit)
64
+ (apply orig r)
65
+ (advice-remove 'get-buffer-create #'nixpkgs--coq-inherit))
66
+ (apply orig r)))
67
+ (advice-add 'scomint-make :around #'nixpkgs--around-scomint-make)
68
+ ; When we have no more coq buffers, tear down the buffer handling
69
+ (defun nixpkgs--decrement-coq-buffer-count ()
70
+ (setq nixpkgs--coq-buffer-count (1- nixpkgs--coq-buffer-count))
71
+ (when (eq nixpkgs--coq-buffer-count 0)
72
+ (advice-remove 'scomint-make #'nixpkgs--around-scomint-make)
73
+ (fmakunbound 'nixpkgs--around-scomint-make)
74
+ (fmakunbound 'nixpkgs--coq-inherit)
75
+ (fmakunbound 'nixpkgs--decrement-coq-buffer-count))))
76
+ (setq nixpkgs--coq-buffer-count (1+ nixpkgs--coq-buffer-count))
77
+ (add-hook 'kill-buffer-hook 'nixpkgs--decrement-coq-buffer-count nil t)
78
+ (setq nixpkgs--is-nixpkgs-coq-buffer t)
79
+ (inherit-local 'nixpkgs--is-nixpkgs-coq-buffer)
49
80
'' ;
50
81
} ;
51
82
0 commit comments