Git Product home page Git Product logo

doom-private's People

Contributors

niklaseklund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doom-private's Issues

blogging

Hey!
I saw your orgmode video presentation...
At the end you showcased placing everything in your blog...
Could you point me to your blog configuration in your config.el or wherever?
Did you use hugo?
Perhaps, if you have time and good will, you could record a video about building an static blog for managing it through Emacs...
Just a suggestion...
Thx for sharing your knowledge...

Make org babel blocks :file output async by default

I saw your wonderful presentation on youtube Org-mode, literate programming in Emacs and thought you might be interested in this idea and the code to do it I had working at one time that could still be working i just tested in vanilla emacs (apparently I had only broke it in my config).

Basically the idea is "ob-async" is nice but I want to be able to see progress from the process as if I were running it in a terminal. So you hijack what org-babel-execute does to files and use make-process.

I want to get around to packaging it up so others can use it eventually, but in case I never do I at least wanted you to have it in exchange for that awesome presentation :)

Here is the code:

(defun my-pass-it-on-filter (filePath proc str)
  "Process each line produced by PROC in STR."
  (interactive)
  (when (buffer-live-p (process-buffer proc))
    (with-current-buffer (process-buffer proc)
      (insert str)
      (goto-char (point-min))
      (while (progn (skip-chars-forward "^\n")
                    (not (eobp)))
        (ignore-errors
          (let ((result (delete-and-extract-region (point-min) (point))))
            (delete-char 1)
            ;; (message (format "writing result '%s' w/newline to %s" result filePath))
            (when (not (file-exists-p filePath))
              (write-region "" nil filePath))
            (write-region (concat result "\n") nil filePath 'append)
            result))))))

      (defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
        "Pass BODY to the Shell process in BUFFER.
          If RESULT-TYPE equals `output' then return a list of the outputs
          of the statements in BODY, if RESULT-TYPE equals `value' then
          return the value of the last statement in BODY."
        (let* ((shebang (cdr (assq :shebang params)))
               (results
                (cond
                 ((or stdin cmdline)	       ; external shell script w/STDIN
                  ;; (map-put params :file file-to-write-progress) ;; TODO htis should happen in one place
                  (let ((script-file (org-babel-temp-file "sh-script-"))
                        (stdin-file (org-babel-temp-file "sh-stdin-"))
                        (padline (not (string= "no" (cdr (assq :padline params))))))
                    (with-temp-file script-file
                      (when shebang (insert shebang "\n"))
                      (when padline (insert "\n"))
                      (insert body))
                    (set-file-modes script-file #o755)
                    (with-temp-file stdin-file (insert (or stdin "")))
                    (with-temp-buffer
                      (call-process-shell-command
                       (concat (if shebang script-file
                                 (format "%s %s" shell-file-name script-file))
                               (and cmdline (concat " " cmdline)))
                       stdin-file
                       (current-buffer))
                      (buffer-string))))
                 (session			; session evaluation
                  ;; (map-put params :file file-to-write-progress) ;; TODO htis should happen in one place
                  (mapconcat
                   #'org-babel-sh-strip-weird-long-prompt
                   (mapcar
                    #'org-trim
                    (butlast
                     (org-babel-comint-with-output
                         (session org-babel-sh-eoe-output t body)
                       (dolist (line (append (split-string (org-trim body) "\n")
                                             (list org-babel-sh-eoe-indicator)))
                         (insert line)
                         (comint-send-input nil t)
                         (while (save-excursion
                                  (goto-char comint-last-input-end)
                                  (not (re-search-forward
                                        comint-prompt-regexp nil t)))
                           (accept-process-output
                            (get-buffer-process (current-buffer))))))
                     2))
                   "\n"))
                 ;; External shell script, with or without a predefined
                 ;; shebang.
                 ((org-string-nw-p shebang)
                  ;; (map-put params :file file-to-write-progress) ;; TODO htis should happen in one place

                  (let ((script-file (org-babel-temp-file "sh-script-"))
                        (padline (not (equal "no" (cdr (assq :padline params))))))
                    (with-temp-file script-file
                      (insert shebang "\n")
                      (when padline (insert "\n"))
                      (insert body))
                    (set-file-modes script-file #o755)
                    (org-babel-eval script-file "")))
                 (t
                  (when (cdr (assq :file params))
                    (message "file was found making process")
                    (make-process :name (format "proc-%s-%s" (file-name-nondirectory (cdr (assq :file params))) (md5 body))
                                  :buffer (format "buf-%s-%s" (file-name-nondirectory (cdr (assq :file params))) (md5 body))
                                  :command (list "sh" "-c" (org-trim body))
                                  :connection-type 'pipe
                                  :filter (apply-partially 'my-pass-it-on-filter (cdr (assq :file params)))))
                  (unless (cdr (assq :file params))
                    (org-babel-eval shell-file-name (org-trim body)))))))
          (unless (cdr (assq :file params)) ;; don't do this if :file exists
            (when results
              (let ((result-params (cdr (assq :result-params params))))
                (org-babel-result-cond result-params
                  results
                  (let ((tmp-file (org-babel-temp-file "sh-")))
                    (with-temp-file tmp-file (insert results))
                    (org-babel-import-elisp-from-file tmp-file))))))))

      (defun org-babel-execute:shell (body params)
        "Execute a block of Shell commands with Babel.
          This function is called by `org-babel-execute-src-block'."
        (when (assq :autolog params)
          (map-put params :file (generate-automatic-log-name)))
        (let* ((session (org-babel-sh-initiate-session
                         (cdr (assq :session params))))
               (stdin (let ((stdin (cdr (assq :stdin params))))
                        (when stdin (org-babel-sh-var-to-string
                                     (org-babel-ref-resolve stdin)))))
               (cmdline (cdr (assq :cmdline params)))
               (full-body (org-babel-expand-body:generic
                           body params (org-babel-variable-assignments:shell params))))
          (org-babel-reassemble-table
           (org-babel-sh-evaluate session full-body params stdin cmdline)
           (org-babel-pick-name
            (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
           (org-babel-pick-name
            (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.