Skip to content

Latest commit

 

History

History
579 lines (507 loc) · 19.1 KB

ess-org.org

File metadata and controls

579 lines (507 loc) · 19.1 KB

using ESS with Emacs Org Mode

meta : setup

experiments

audio problems

trying to get microphone to work. used arch pulseaudio troubleshooting page. “PulseAudio uses wrong microphone” seemed to do it, with alsamixer:

  • F6
  • choose actual hardware
  • F5 (i used F4)
  • select “Capture” (“input source” i didn’t see)

then seemed to work, but was overmodulating. used alsamixer, lowered level. (took a couple of times to take effect?)

also

pactl list sources short
arecord -l
pavucontrol

(click on “Input Devices”, see that the other microphones – Front, Headset – are unplugged, only Internal is plugged in.

meta : tools, etc

https://obsproject.com/wiki/OBS-Studio-Quickstart obs, on arch linux (part of the obs-studio package).

https://github.com/ess-intro/ess-intro/issues is where most discussion happens.

vterm is pretty fast.

to get little modifier key thing:

pip install git+https://github.com/scottkirkwood/key-mon

but, it doesn’t like my control key.

screenkey is an arch package:

rm -f ~/.config/screenkey.json && screenkey -s large --geometry 400x200-1-1 --ignore Caps_Lock --key-mode composed --bg-color blue --persist --timeout 1 &

literate-elisp – load elisp into emacs directly from org source blocks

elisp code

:header-args+: :tangle ./tangled/el-org.el

org-filter-by-argument-value

(require 'ob-core)

(defun org-filter-by-argument-value (arg values &optional locs negate)
  "Return the subset of LOCS (default: (point)) that correspond
to evaluatable locations in the current buffer whose
\"info\" (org-babel-get-src-block-info) argument parameter
contains an argument ARG with a value in VALUES."
  (let ((pt (point))
        (results (mapcar (lambda (l)
                           (progn
                             (goto-char l)
                             (let* ((info (org-babel-get-src-block-info t))
                                    (value (cdr (assoc arg (nth 2 info)))))
                               (if (or
                                    (not info) ; call site? XXX should filter?
                                    (and negate (not (member value values)))
                                    (and (not negate) (member value values)))
                                   l
                                 nil))))
                         (if locs locs (list (point))))))
    (goto-char pt)
    (reverse (seq-filter (lambda(x) x) results))))

for each block in the (whichever) buffer

  • if :eval is not (some form of) “no”, offer it up for evaluation
(require 'ob-core)

(defun org-walk-and-evaluate (&optional arg values dontnegate)
    "Based on org-babel-execute-buffer, with the main difference
that we return the locations of the blocks we evaluated.  Probably
should just use o-b-e-b."
    (let ((result nil)
          (arg (if arg arg ':eval))
          (values (if values
                      values
                    (list "never" "never-export" "no" "no-export")))
          (negate (if dontnegate nil t)))
      (save-window-excursion
        (org-babel-map-executables nil
          (if (org-filter-by-argument-value
               arg values nil negate)
              (progn
                ;; fine, this is horrible.
                (setq result (append result (list (point))))
                ;; flat-out copied from (org-babel-execute-buffer)
                (if (memq (org-element-type (org-element-context))
                          '(babel-call inline-babel-call))
                    (org-babel-lob-execute-maybe)
                  (org-babel-execute-src-block))
                (point)))))
      result))

find all [non-]org blocks

(require 'ob-core)
(require 'org-element)

(defun org-get-org-blocks (&optional complement)
  "return the starting location of each org (language) source
block in the current buffer; returns the complement of that set
if COMPLEMENT is true"
  (let ((blocks nil))
    (org-babel-map-executables nil
      (let* ((context (org-element-context))
             (ctype (car context))
             (clist (cadr context)))
        (if (or (memq ctype '(babel-call inline-babel-call))
                (xor (equal (plist-get clist :language) "org") complement))
            (setq blocks (cons (point) blocks)))))
    (reverse blocks)))

orgify-blocks: orgify all non-org blocks

(defun orgify-blocks (locs)
  ;; take each block that starts at a location in LOCS and insert it
  ;; between #+begin_src org...#+end_src
  (let ((to-insert "#+begin_src org :exports code :noweb nil\n#+end_src\n")
        ;; we work on the reversed list, from the end of the buffer to the
        ;; beginning, since our actions are going to change line numbers
        (slocs (sort locs '>)))
    (mapc
     (lambda (l)
       ;; (debug)
       (goto-char l)
       (let* ((context (org-element-context))
              (ctype (car context))
              (clist (cadr context))
              (src-begin (plist-get clist :begin))
              (src-end (plist-get clist :end ))
              (results-begin (org-babel-where-is-src-block-result))
              (results-end (if results-begin
                               (progn (goto-char results-begin)(org-babel-result-end))
                             nil))
              (begin (progn
                       (goto-char src-begin)
                       (if (member ctype '(inline-src-block inline-babel-call))
                           (progn (org-backward-paragraph) (forward-char)))
                       (point)))
              (end (progn
                     (goto-char (if results-end results-end src-end))
                     (if (member ctype '(inline-src-block inline-babel-call))
                         (progn (org-forward-paragraph) (backward-char)))
                     (re-search-backward "^..*$")
                     (org-forward-paragraph)
                     (backward-char)
                     (point)))
              (contents (delete-and-extract-region begin end)))
         (insert to-insert)
         (goto-char begin)            ; go back to beginning of new src block
         (org-babel-do-in-edit-buffer
          (insert contents)))) ; now, in edit buffer, insert previuos contents
     slocs)))
(defun orgify-all-non-org-blocks ()
  ;; take every non-org block, as well as call site, and insert it
  ;; between #+begin_src org...#+end_src
  (let ((pt (point))                    ; XXX s/b marker?
        (filtered (org-get-org-blocks t)))
    (unwind-protect
        (save-window-excursion
          (orgify-blocks filtered))
      (goto-char pt))
  (reverse filtered)))

resultify-non-org-blocks: evaluate all(*) the non-org blocks in the buffer

(*) if :exports “results” or “both”, evaluate it

(defun resultify-non-org-blocks ()
    (let (results
          (pt (point)))
      (org-babel-eval-wipe-error-buffer)
      (unwind-protect
          (save-window-excursion
            (setq results (org-walk-and-evaluate
                           ':exports
                           (list "results" "both")
                           (org-get-org-blocks t)))))
        results))

resultify-org-blocks: evaluate (internals of) all(*) the org blocks in the buffer

(*) if :exports “results” or “both”, evaluate all blocks in the org block

for each org-in-org block that :exports either “results” or “both”, open up an edit buffer, and evaluate all internal code that :exports either “results” or “both”.

	(defun resultify-org-blocks ()
		(let (results
					(pt (point)))
			(org-babel-eval-wipe-error-buffer)
			(unwind-protect
					(save-window-excursion
						(mapc
						 (lambda (l)
							 (goto-char l)
							 (org-babel-do-in-edit-buffer
								(let ((result (org-walk-and-evaluate)))
									(org-edit-src-save)
									(setq results (append results (list (list l result)))))))
						 (org-filter-by-argument-value
							':exports (list "results" "both") (org-get-org-blocks))))
				(goto-char pt))
			results))

macrify: expand all macros, optionally filling paragraphs

this routine expands all macros in the current buffer

(defun macrify (&optional fill)
  "expand all macros in the current buffer.  if FILL is non-nil,
fill all the paragraphs where strings similar to macros (i.e.,
starting with three curly left braces) were found"
  (let* ((entry-point (point))
         (markers
          (when fill
            (goto-char (point-min))
            (-unfold (lambda (x)
                       (let ((next (search-forward "{{{" nil t)))
                         (if next
                             (list (point-marker)))))
                     nil)
            )))
    (org-macro-replace-all (org-macro--collect-macros))
    (dolist (marker markers)
      (goto-char (marker-position marker))
      (let ((oec (org-element-context)))
        ;; make sure we are in a paragraph or the child of a paragraph
        ;; (for example, if we are a verbatim region in a paragraph)
        (if (or
             (equal (car oec) 'paragraph)
             (equal (car (plist-get (cadr oec) :parent)) 'paragraph))
            (org-fill-paragraph))))
      (goto-char entry-point)))

org-publish-project-alist

(setq org-publish-project-alist
      '(("ess-org-demo-results-html"
         :base-directory "./artefacts"
         :publishing-directory "./artefacts"
         :exclude ".*"
         :include ("ess-org-demo-results.org")
         :publishing-function org-html-publish-to-html)
        ("ess-org-demo-results-pdf"
         :base-directory "./artefacts"
         :publishing-directory "./artefacts"
         :exclude ".*"
         :include ("ess-org-demo-results.org")
         :publishing-function org-latex-publish-to-pdf)
        ("ess-org-beamer-html"
         :base-directory "./"
         :publishing-directory "./artefacts"
         :exclude ".*"
         :include ("ess-org-beamer.org")
         :publishing-function org-html-publish-to-html)
        ("ess-org-beamer-pdf"
         :base-directory "./"
         :publishing-directory "./artefacts"
         :exclude ".*"
         :include ("ess-org-beamer.org")
         :publishing-function org-beamer-publish-to-pdf)
        ("ess-org" :components ("ess-org-demo-results-html"
                                "ess-org-demo-results-pdf"
                                "ess-org-beamer-html"
                                "ess-org-beamer-pdf"))))
(provide 'el-org)

ggm-twbs

this is the twbs code, with some of mine in front to re-arrange the (normally exported) .html file into the right shape for twbs’ bootstrap’ping.

NB: as currently written, a #+title line – which produces an <h1> right at the beginning, messes up the logic.

(this code came from my photoTagger project.)

XXX i should make this an NPM package. maybe that would also get me to upgrade it to a more recent bootstrap.

(what i’d really like is to feed this back into the Org Mode source. hint, hint.)

javascript
$(function() {
    'use strict';

    // begin ggm-twbs: this code beats the exported .html file into
    // twbs-shape

    $('#content').addClass("container");

    // here we are assuming the first child is the table of contents.
    // XXX if there is no toc?  XXX if it elsewhere in the .html file?
    $("#table-of-contents")
        .children()
        .first()
        .remove();
    $("#table-of-contents")
        .children()
        .wrapAll('<div class="col-md-3 col-md-push-9"></div>');
    $("#table-of-contents")
        .children()
        .unwrap();
    $("#table-of-contents").remove();

    // fixed olsun
    $('#text-table-of-contents').addClass("bs-docs-sidebar");

    // for scrollspy (below), add class nav to the toc
    $("#text-table-of-contents ul").addClass("nav");

    // then, *each* (not *all*, though maybe that is what we should
    // do?) of the rest are wrapped in the col-md-9/col-md-pull-3
    // div's
    $("#content").children()
        .first()
        .siblings()
        .wrapAll('<div class="col-md-9 col-md-pull-3"></div>');

    $('#content').children().wrapAll('<div class="row">');
    // end ggm-twbs


    $('.bs-docs-sidebar li').first().addClass('active');

    $(document.body).scrollspy({target: '.bs-docs-sidebar'});

    $('.bs-docs-sidebar').affix();
});
css

my mods to twbs to allow exporting with normal org-mode html exporter, then (in javascript, on the client) adapt the generated html to twbs, need (well…) an external .css file. these are pretty much direct from a .html file twbs-exported from a .org file.

/* org mode styles on top of twbs */

html {
    position: relative;
    min-height: 100%;
}

body {
    font-size: 18px;
    margin-bottom: 105px;
}

footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 101px;
    background-color: #f5f5f5;
}

footer > div {
    padding: 10px;
}

footer p {
    margin: 0 0 5px;
    text-align: center;
    font-size: 16px;
}

#table-of-contents {
    margin-top: 20px;
    margin-bottom: 20px;
}

blockquote p {
    font-size: 18px;
}

pre {
    font-size: 16px;
}

.footpara {
    display: inline-block;
}

figcaption {
    font-size: 16px;
    color: #666;
    font-style: italic;
    padding-bottom: 15px;
}

/* from twbs docs */

.bs-docs-sidebar.affix {
    position: static;
}
@media (min-width: 768px) {
    .bs-docs-sidebar {
        padding-left: 20px;
    }
}

/* All levels of nav */
.bs-docs-sidebar .nav > li > a {
    display: block;
    padding: 4px 20px;
    font-size: 14px;
    font-weight: 500;
    color: #999;
}
.bs-docs-sidebar .nav > li > a:hover,
.bs-docs-sidebar .nav > li > a:focus {
    padding-left: 19px;
    color: #A1283B;
    text-decoration: none;
    background-color: transparent;
    border-left: 1px solid #A1283B;
}
.bs-docs-sidebar .nav > .active > a,
.bs-docs-sidebar .nav > .active:hover > a,
.bs-docs-sidebar .nav > .active:focus > a {
    padding-left: 18px;
    font-weight: bold;
    color: #A1283B;
    background-color: transparent;
    border-left: 2px solid #A1283B;
}

/* Nav: second level (shown on .active) */
.bs-docs-sidebar .nav .nav {
    display: none; /* Hide by default, but at >768px, show it */
    padding-bottom: 10px;
}
.bs-docs-sidebar .nav .nav > li > a {
    padding-top: 1px;
    padding-bottom: 1px;
    padding-left: 30px;
    font-size: 12px;
    font-weight: normal;
}
.bs-docs-sidebar .nav .nav > li > a:hover,
.bs-docs-sidebar .nav .nav > li > a:focus {
    padding-left: 29px;
}
.bs-docs-sidebar .nav .nav > .active > a,
.bs-docs-sidebar .nav .nav > .active:hover > a,
.bs-docs-sidebar .nav .nav > .active:focus > a {
    padding-left: 28px;
    font-weight: 500;
}

/* Nav: third level (shown on .active) */
.bs-docs-sidebar .nav .nav .nav {
    padding-bottom: 10px;
}
.bs-docs-sidebar .nav .nav .nav > li > a {
    padding-top: 1px;
    padding-bottom: 1px;
    padding-left: 40px;
    font-size: 12px;
    font-weight: normal;
}
.bs-docs-sidebar .nav .nav .nav > li > a:hover,
.bs-docs-sidebar .nav .nav .nav > li > a:focus {
    padding-left: 39px;
}
.bs-docs-sidebar .nav .nav .nav > .active > a,
.bs-docs-sidebar .nav .nav .nav > .active:hover > a,
.bs-docs-sidebar .nav .nav .nav > .active:focus > a {
    padding-left: 38px;
    font-weight: 500;
}

/* Show and affix the side nav when space allows it */
@media (min-width: 992px) {
    .bs-docs-sidebar .nav > .active > ul {
        display: block;
    }
    /* Widen the fixed sidebar */
    .bs-docs-sidebar.affix,
    .bs-docs-sidebar.affix-bottom {
        width: 213px;
    }
    .bs-docs-sidebar.affix {
        position: fixed; /* Undo the static from mobile first approach */
        top: 20px;
    }
    .bs-docs-sidebar.affix-bottom {
        position: absolute; /* Undo the static from mobile first approach */
    }
    .bs-docs-sidebar.affix .bs-docs-sidenav,.bs-docs-sidebar.affix-bottom .bs-docs-sidenav {
        margin-top: 0;
        margin-bottom: 0
    }
}
@media (min-width: 1200px) {
    /* Widen the fixed sidebar again */
    .bs-docs-sidebar.affix-bottom,
    .bs-docs-sidebar.affix {
        width: 263px;
    }
}

and, this is html to enable ggm-twbs:

<link  href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="./ggm-twbs.css" rel="stylesheet"/>
<script src="./ggm-twbs.js"></script>