rpav / cmake-build.el

CMake building with multiple targets, run configurations, and interactive menu
GNU General Public License v3.0
14 stars 5 forks source link

cmake-build-never-split nil errors in cmake-build--compile again #15

Closed laurynas-biveinis closed 4 years ago

laurynas-biveinis commented 4 years ago

The return of https://github.com/rpav/cmake-build.el/issues/10:

Debugger entered--Lisp error: (error "No buffer named *Build unodb/gcc-debug-asan: test*")
  set-buffer("*Build unodb/gcc-debug-asan: test*")
  (save-current-buffer (set-buffer buffer-name) (set (make-local-variable (quote compilation-directory)) actual-directory) (set (make-local-variable (quote default-directory)) actual-directory))
  (if (get-buffer-process buffer-name) (message "Already building %s/%s" (projectile-project-name) (symbol-name cmake-build-profile)) (save-current-buffer (set-buffer buffer-name) (set (make-local-variable (quote compilation-directory)) actual-directory) (set (make-local-variable (quote default-directory)) actual-directory)) (let* ((compilation-buffer-name-function (function cmake-build--build-buffer-name))) (let* ((--cl-run-compile-- (function (lambda nil (compile ...))))) (progn (let ((w (get-buffer-window buffer-name t))) (if (and w (not ...)) (if cmake-build-switch-to-build (progn ... ...) (let ... ...)) (funcall --cl-run-compile--))))) (if sentinel (progn (let ((process (get-buffer-process buffer-name))) (if (process-live-p process) (progn (set-process-sentinel process ...)))))) (save-current-buffer (set-buffer buffer-name) (mapcar (function (lambda (w) (set-window-point w (point-max)))) (get-buffer-window-list buffer-name nil t)) (visual-line-mode 1))))
  (let* ((did-split (cmake-build--split-to-buffer buffer-name other-buffer-name)) (display-buffer-alist (if did-split (cons (list buffer-name (function display-buffer-no-window)) display-buffer-alist) display-buffer-alist)) (actual-directory default-directory)) (if (get-buffer-process buffer-name) (message "Already building %s/%s" (projectile-project-name) (symbol-name cmake-build-profile)) (save-current-buffer (set-buffer buffer-name) (set (make-local-variable (quote compilation-directory)) actual-directory) (set (make-local-variable (quote default-directory)) actual-directory)) (let* ((compilation-buffer-name-function (function cmake-build--build-buffer-name))) (let* ((--cl-run-compile-- (function (lambda nil ...)))) (progn (let ((w ...)) (if (and w ...) (if cmake-build-switch-to-build ... ...) (funcall --cl-run-compile--))))) (if sentinel (progn (let ((process ...)) (if (process-live-p process) (progn ...))))) (save-current-buffer (set-buffer buffer-name) (mapcar (function (lambda (w) (set-window-point w ...))) (get-buffer-window-list buffer-name nil t)) (visual-line-mode 1)))))

The culprit is recently added

      (with-current-buffer buffer-name
        (setq-local compilation-directory actual-directory)
        (setq-local default-directory actual-directory))

where buffer-name is nil.

If I am not misunderstanding how elisp local bindings of global vars work, the following should work (it resolves the immediate error for me, but gives "Unused lexical variable `variable compilation-directory'"):

modified   cmake-build.el
@@ -278,11 +278,10 @@ use Projectile to determine the root on a buffer-local basis, instead.")
         (message "Already building %s/%s"
                  (projectile-project-name)
                  (symbol-name cmake-build-profile))
-      (with-current-buffer buffer-name
-        (setq-local compilation-directory actual-directory)
-        (setq-local default-directory actual-directory))
       ;; compile saves buffers; rely on this now
-      (let* ((compilation-buffer-name-function #'cmake-build--build-buffer-name))
+      (let* ((compilation-buffer-name-function #'cmake-build--build-buffer-name)
+             (compilation-directory actual-directory)
+             (default-directory actual-directory))
         (cl-flet ((run-compile () (compile (concat "time " command))))
           (let ((w (get-buffer-window buffer-name t)))
             (if (and w (not (eql (get-buffer-window) w)))
rpav commented 4 years ago

Fixed in a more general sense of checking if we're actually somewhere valid before trying to do things, and giving some possibly-useful information otherwise. Let me know if this crops up elsewhere; I tried to cut it off at the two main points (compile/run).

laurynas-biveinis commented 4 years ago

This replaced an Elisp error with user error - but cmake-build-never-split set to nil still does not work: now it refuses to compile instead of doing what M-x compile would.

rpav commented 4 years ago

Ah right I noticed splitting was still splitting incorrectly (in too-small windows) at some point and forgot to swing back around. The three cases ought to work now based on my testing (never-split, split threshold, regular split).

(Note in the above/original post, LET will not work instead of setq-local, because buffer-local variables are in a different context, so to speak. Thus the message about compilation-directory, which isn't a defvar variable, but a lexical. In short, buffer locals are separate from dynamic scope.)