Function: org-babel-haskell-initiate-session

org-babel-haskell-initiate-session is a byte-compiled function defined in ob-haskell.el.gz.

Signature

(org-babel-haskell-initiate-session &optional SESSION-NAME PARAMS)

Documentation

Initiate a haskell session.

Return the initialized session, i.e. the buffer for this session. When SESSION-NAME is nil, use a global session named
"*ob-haskell*". When SESSION-NAME is the string "none", use
a temporary buffer. Else, (re)use the session named SESSION-NAME. The buffer name is the session name. See also org-babel-haskell-with-session.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-haskell.el.gz
(defun org-babel-haskell-initiate-session (&optional session-name _params)
  "Initiate a haskell session.
Return the initialized session, i.e. the buffer for this session.
When SESSION-NAME is nil, use a global session named
\"*ob-haskell*\".  When SESSION-NAME is the string \"none\", use
a temporary buffer.  Else, (re)use the session named
SESSION-NAME.  The buffer name is the session name.  See also
`org-babel-haskell-with-session'."
  (org-require-package 'inf-haskell "haskell-mode")
  (cond
   ((equal "none" session-name)
    ;; Temporary buffer name.
    (setq session-name (generate-new-buffer-name " *ob-haskell-tmp*")))
   ((eq nil session-name)
    ;; The global default session. As haskell-mode is using the buffer
    ;; named "*haskell*", we stay away from it.
    (setq session-name "*ob-haskell*"))
   ((not (stringp session-name))
    (error "session-name must be a string")))
  (let ((session (get-buffer session-name)))
    ;; NOTE: By construction, as SESSION-NAME is a string, session is
    ;; either nil or a live buffer.
    (save-window-excursion
      (or (org-babel-comint-buffer-livep session)
          (let ((inferior-haskell-buffer session))
            ;; As inferior-haskell expects the buffer to be named
            ;; "*haskell*", we temporarily rename it while executing
            ;; `run-haskell' (unless the user explicitly requested to
            ;; use the name "*haskell*").
            (when (not (equal "*haskell*" session-name))
              (when (bufferp session)
                (when (bufferp "*haskell*")
                  (user-error "Conflicting buffer '*haskell*', rename it or kill it"))
                (with-current-buffer session (rename-buffer "*haskell*"))))
            (unwind-protect
                (let ((inferior-haskell-root-dir default-directory))
                  (run-haskell)
                  (sleep-for 0.25)
                  (setq session inferior-haskell-buffer))
              (when (and (not (equal "*haskell*" session-name))
                         (bufferp session))
                (with-current-buffer session (rename-buffer session-name))))
            ;; Disable secondary prompt: If we do not do this,
            ;; org-comint may treat secondary prompts as a part of
            ;; output.
            (org-babel-comint-input-command
             session
             ":set prompt-cont \"\"")
            session)
          ))
    session))