Emacs factor mode: Fail gracefully when the listener is not running.
							parent
							
								
									d7587282fd
								
							
						
					
					
						commit
						95bf38f5ee
					
				| 
						 | 
					@ -476,7 +476,7 @@ buffer."
 | 
				
			||||||
  (setq factor-indent-width (factor--guess-indent-width))
 | 
					  (setq factor-indent-width (factor--guess-indent-width))
 | 
				
			||||||
  (setq indent-tabs-mode nil)
 | 
					  (setq indent-tabs-mode nil)
 | 
				
			||||||
  ;; ElDoc
 | 
					  ;; ElDoc
 | 
				
			||||||
  (set (make-local-variable 'eldoc-documentation-function) 'factor--see-current-word)
 | 
					  (set (make-local-variable 'eldoc-documentation-function) 'factor--eldoc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (run-hooks 'factor-mode-hook))
 | 
					  (run-hooks 'factor-mode-hook))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -503,11 +503,12 @@ buffer."
 | 
				
			||||||
  (with-current-buffer factor--listener-buffer
 | 
					  (with-current-buffer factor--listener-buffer
 | 
				
			||||||
    (factor-listener-mode)))
 | 
					    (factor-listener-mode)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun factor--listener-process ()
 | 
					(defun factor--listener-process (&optional start)
 | 
				
			||||||
  (or (and (buffer-live-p factor--listener-buffer)
 | 
					  (or (and (buffer-live-p factor--listener-buffer)
 | 
				
			||||||
           (get-buffer-process factor--listener-buffer))
 | 
					           (get-buffer-process factor--listener-buffer))
 | 
				
			||||||
      (progn (factor--listener-start-process)
 | 
					      (when start
 | 
				
			||||||
             (factor--listener-process))))
 | 
					        (factor--listener-start-process)
 | 
				
			||||||
 | 
					        (factor--listener-process t))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;###autoload
 | 
					;;;###autoload
 | 
				
			||||||
(defalias 'switch-to-factor 'run-factor)
 | 
					(defalias 'switch-to-factor 'run-factor)
 | 
				
			||||||
| 
						 | 
					@ -515,7 +516,7 @@ buffer."
 | 
				
			||||||
(defun run-factor (&optional arg)
 | 
					(defun run-factor (&optional arg)
 | 
				
			||||||
  "Show the factor-listener buffer, starting the process if needed."
 | 
					  "Show the factor-listener buffer, starting the process if needed."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (let ((buf (process-buffer (factor--listener-process)))
 | 
					  (let ((buf (process-buffer (factor--listener-process t)))
 | 
				
			||||||
        (pop-up-windows factor-listener-window-allow-split))
 | 
					        (pop-up-windows factor-listener-window-allow-split))
 | 
				
			||||||
    (if factor-listener-use-other-window
 | 
					    (if factor-listener-use-other-window
 | 
				
			||||||
        (pop-to-buffer buf)
 | 
					        (pop-to-buffer buf)
 | 
				
			||||||
| 
						 | 
					@ -538,15 +539,16 @@ buffer."
 | 
				
			||||||
;;; Factor listener interaction:
 | 
					;;; Factor listener interaction:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun factor--listener-send-cmd (cmd)
 | 
					(defun factor--listener-send-cmd (cmd)
 | 
				
			||||||
  (let* ((out (get-buffer-create "*factor messages*"))
 | 
					  (let ((proc (factor--listener-process)))
 | 
				
			||||||
         (beg (with-current-buffer out (goto-char (point-max))))
 | 
					    (when proc
 | 
				
			||||||
         (proc (factor--listener-process)))
 | 
					      (let* ((out (get-buffer-create "*factor messages*"))
 | 
				
			||||||
    (comint-redirect-send-command-to-process cmd out proc nil t)
 | 
					             (beg (with-current-buffer out (goto-char (point-max)))))
 | 
				
			||||||
    (with-current-buffer factor--listener-buffer
 | 
					        (comint-redirect-send-command-to-process cmd out proc nil t)
 | 
				
			||||||
      (while (not comint-redirect-completed) (sleep-for 0 1)))
 | 
					        (with-current-buffer factor--listener-buffer
 | 
				
			||||||
    (with-current-buffer out
 | 
					          (while (not comint-redirect-completed) (sleep-for 0 1)))
 | 
				
			||||||
      (split-string (buffer-substring-no-properties beg (point-max))
 | 
					        (with-current-buffer out
 | 
				
			||||||
                    "[\"\f\n\r\v]+" t))))
 | 
					          (split-string (buffer-substring-no-properties beg (point-max))
 | 
				
			||||||
 | 
					                        "[\"\f\n\r\v]+" t))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;;; Current vocabulary:
 | 
					;;;;; Current vocabulary:
 | 
				
			||||||
(make-variable-buffer-local
 | 
					(make-variable-buffer-local
 | 
				
			||||||
| 
						 | 
					@ -581,15 +583,13 @@ buffer."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;;; Synchronous interaction:
 | 
					;;;;; Synchronous interaction:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun factor--listener-sync-cmds (cmds &optional vocab)
 | 
					(defsubst factor--listener-vocab-cmds (cmds &optional vocab)
 | 
				
			||||||
  (factor--with-vocab vocab
 | 
					  (factor--with-vocab vocab
 | 
				
			||||||
    (mapcar #'(lambda (c)
 | 
					    (mapcar #'factor--listener-send-cmd cmds)))
 | 
				
			||||||
                (comint-redirect-results-list-from-process
 | 
					 | 
				
			||||||
                 (factor--listener-process) c ".+" 0))
 | 
					 | 
				
			||||||
            cmds)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defsubst factor--listener-sync-cmd (cmd &optional vocab)
 | 
					(defsubst factor--listener-vocab-cmd (cmd &optional vocab)
 | 
				
			||||||
  (car (factor--listener-sync-cmds (list cmd) vocab)))
 | 
					  (factor--with-vocab vocab
 | 
				
			||||||
 | 
					    (factor--listener-send-cmd cmd)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;;;; Interface: see
 | 
					;;;;; Interface: see
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -618,11 +618,15 @@ buffer."
 | 
				
			||||||
  (let ((word (or word (factor--symbol-at-point))))
 | 
					  (let ((word (or word (factor--symbol-at-point))))
 | 
				
			||||||
    (when word
 | 
					    (when word
 | 
				
			||||||
      (let ((answer (factor--listener-send-cmd (format "\\ %s see" word))))
 | 
					      (let ((answer (factor--listener-send-cmd (format "\\ %s see" word))))
 | 
				
			||||||
        (factor--see-ans-to-string answer)))))
 | 
					        (and answer (factor--see-ans-to-string answer))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defalias 'factor--eldoc 'factor--see-current-word)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun factor-see-current-word (&optional word)
 | 
					(defun factor-see-current-word (&optional word)
 | 
				
			||||||
  "Echo in the minibuffer information about word at point."
 | 
					  "Echo in the minibuffer information about word at point."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
 | 
					  (unless (factor--listener-process)
 | 
				
			||||||
 | 
					    (error "No factor listener running. Try M-x run-factor"))
 | 
				
			||||||
  (let ((word (or word (factor--symbol-at-point)))
 | 
					  (let ((word (or word (factor--symbol-at-point)))
 | 
				
			||||||
        (msg (factor--see-current-word word)))
 | 
					        (msg (factor--see-current-word word)))
 | 
				
			||||||
    (if msg (message "%s" msg)
 | 
					    (if msg (message "%s" msg)
 | 
				
			||||||
| 
						 | 
					@ -742,6 +746,8 @@ buffer."
 | 
				
			||||||
(defvar factor--help-history nil)
 | 
					(defvar factor--help-history nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun factor--listener-show-help (&optional see)
 | 
					(defun factor--listener-show-help (&optional see)
 | 
				
			||||||
 | 
					  (unless (factor--listener-process)
 | 
				
			||||||
 | 
					    (error "No running factor listener. Try M-x run-factor"))
 | 
				
			||||||
  (let* ((def (factor--symbol-at-point))
 | 
					  (let* ((def (factor--symbol-at-point))
 | 
				
			||||||
         (prompt (format "See%s help on%s: " (if see " short" "")
 | 
					         (prompt (format "See%s help on%s: " (if see " short" "")
 | 
				
			||||||
                         (if def (format " (%s)" def) "")))
 | 
					                         (if def (format " (%s)" def) "")))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue