Skip to content
Snippets Groups Projects
Commit c0e1cb0f authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Test avec un exemple pugs

Requière pas mal de modules emacs :

(eval-when-compile
  (require 'easy-mmode)
  (require 'ox))

(use-package ox
  :config
  (define-minor-mode unpackaged/org-export-html-with-useful-ids-mode
    "Attempt to export Org as HTML with useful link IDs.
Instead of random IDs like \"#orga1b2c3\", use heading titles,
made unique when necessary."
    :global t
    (if unpackaged/org-export-html-with-useful-ids-mode
        (advice-add #'org-export-get-reference :override #'unpackaged/org-export-get-reference)
      (advice-remove #'org-export-get-reference #'unpackaged/org-export-get-reference)))

  (defun unpackaged/org-export-get-reference (datum info)
    "Like `org-export-get-reference', except uses heading titles instead of random numbers."
    (let ((cache (plist-get info :internal-references)))
      (or (car (rassq datum cache))
          (let* ((crossrefs (plist-get info :crossrefs))
                 (cells (org-export-search-cells datum))
                 ;; Preserve any pre-existing association between
                 ;; a search cell and a reference, i.e., when some
                 ;; previously published document referenced a location
                 ;; within current file (see
                 ;; `org-publish-resolve-external-link').
                 ;;
                 ;; However, there is no guarantee that search cells are
                 ;; unique, e.g., there might be duplicate custom ID or
                 ;; two headings with the same title in the file.
                 ;;
                 ;; As a consequence, before re-using any reference to
                 ;; an element or object, we check that it doesn't refer
                 ;; to a previous element or object.
                 (new (or (cl-some
                           (lambda (cell)
                             (let ((stored (cdr (assoc cell crossrefs))))
                               (when stored
                                 (let ((old (org-export-format-reference stored)))
                                   (and (not (assoc old cache)) stored)))))
                           cells)
                          (when (org-element-property :raw-value datum)
                            ;; Heading with a title
                            (unpackaged/org-export-new-title-reference datum cache))
                          ;; NOTE: This probably breaks some Org Export
                          ;; feature, but if it does what I need, fine.
                          (org-export-format-reference
                           (org-export-new-reference cache))))
                 (reference-string new))
            ;; Cache contains both data already associated to
            ;; a reference and in-use internal references, so as to make
            ;; unique references.
            (dolist (cell cells) (push (cons cell new) cache))
            ;; Retain a direct association between reference string and
            ;; DATUM since (1) not every object or element can be given
            ;; a search cell (2) it permits quick lookup.
            (push (cons reference-string datum) cache)
            (plist-put info :internal-references cache)
            reference-string))))

  (defun unpackaged/org-export-new-title-reference (datum cache)
    "Return new reference for DATUM that is unique in CACHE."
    (cl-macrolet ((inc-suffixf (place)
                               `(progn
                                  (string-match (rx bos
                                                    (minimal-match (group (1+ anything)))
                                                    (optional "--" (group (1+ digit)))
                                                    eos)
                                                ,place)
                                  ;; HACK: `s1' instead of a gensym.
                                  (-let* (((s1 suffix) (list (match-string 1 ,place)
                                                             (match-string 2 ,place)))
                                          (suffix (if suffix
                                                      (string-to-number suffix)
                                                    0)))
                                    (setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
      (let* ((title (org-element-property :raw-value datum))
             (ref (url-hexify-string (substring-no-properties title)))
             (parent (org-element-property :parent datum)))
        (while (--any (equal ref (car it))
                      cache)
          ;; Title not unique: make it so.
          (if parent
              ;; Append ancestor title.
              (setf title (concat (org-element-property :raw-value parent)
                                  "--" title)
                    ref (url-hexify-string (substring-no-properties title))
                    parent (org-element-property :parent parent))
            ;; No more ancestors: add and increment a number.
            (inc-suffixf ref)))
        ref))))

(defun org-babel-execute:pugs (body params)
  "Execute a block of pugs code with org-babel."
  (let ((in-file (org-babel-temp-file "n" ".pugs"))
        (verbosity (or (cdr (assq :verbosity params)) 0)))
    (with-temp-file in-file
      (insert body))
    (org-babel-eval
     (format "~/src/pugs/build/pugs --no-color %s"
             (org-babel-process-file-name in-file))
     "")))
parent 1ef1e8e8
Branches
No related tags found
No related merge requests found
#+SETUPFILE: https://fniessen.github.io/org-html-themes/setup/theme-bigblow.setup
#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup
#+STARTUP: org-pretty-entities entitiespretty
#+PROPERTY: header-args :comments yes
#+PROPERTY: header-args :comments no
#+OPTIONS: h:3 num:t toc:3
#+TITLE: Exemple de document interactif
#+OPTIONS: author:nil date:nil
......@@ -56,6 +56,30 @@ python pour approcher (bien mal) la valeur de $\pi$.
#+RESULTS:
: pi ~ 3.14063710098594
** pugs
#+BEGIN_SRC pugs :exports both :results output :post
let f:R -> R, x -> 2*x+1;
cout << 2*f(3) << "\n";
#+END_SRC
#+RESULTS:
#+begin_example
----------------- pugs exec info ----------------------
MPI number of ranks 1
Kokkos::OpenMP thread_pool_topology[ 1 x 8 x 1 ]
-------------------------------------------------------
,* setting random seed to 3830406915
Parsing file /tmp/babel-dXeodt/nwRYD2u.pugs ...
- loaded modules
- checked symbols declaration
- build node data types
- checked node data types
-------------------------------------------------------
Executing AST...
14
#+end_example
* Équations
Il est possible d'écrire des maths normalement dans le texte ($\partial_t u -
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment