1

I would like to prepend a $ sign to the front of every non empty line in the export. Comments should be skipped if possible. Couldn't find an option for it.

Is there an option? If not is there a quick way to achieve that with some elisp?

  • Is the $ the comment sign of the source? – Dieter.Wilhelm Oct 9 '15 at 5:24
  • @Dieter.Wilhelm No, the source is a sh(shell) block. – clemera Oct 9 '15 at 13:28
  • I see, did you had a look at export filters orgmode.org/manual/Advanced-configuration.html ? – Dieter.Wilhelm Oct 9 '15 at 14:42
  • @Dieter.Wilhelm Thanks for the pointer. Seems like this is the right way to solve this. I will look into that. – clemera Oct 9 '15 at 15:04
  • @Dieter.Wilhelm Thanks, it worked. See my answer. – clemera Oct 9 '15 at 18:06
1

After some elisp hacking, this seems to work:

(defun my-add-dollar-sign (text backend info)
  "Add a dollar sign to the shell export blocks in html exports"
  (when (org-export-derived-backend-p backend 'html)
    (with-temp-buffer
      (insert text)
      (goto-char (point-min))
      (search-forward "<pre class=\"src src-sh\">")
      (save-restriction
        (narrow-to-region (point)
                          (save-excursion
                            (search-forward "</pre>")
                            (goto-char (match-beginning 0))
                            (point)))
        (while (not (eobp))
          (unless (or (looking-at
                       (concat "<span style=\"color: "
                               (face-attribute 'font-lock-comment-face :foreground)
                               ";\">"))
                      (looking-at "[[:space:]]*$"))
            (insert "$ "))
          (forward-line 1)))
      (buffer-string))))



(require 'ox)
(add-to-list 'org-export-filter-src-block-functions
             'my-add-dollar-sign)
| improve this answer | |
0

Try:

#+begin_src shell :noweb yes :tangle somefile.sh
  $ <<prefix-stuff>>
#+end_src

#+name: prefix-stuff
#+begin_src shell
  thing-you-wanted-prefixed-here
  with-as-many-lines-as-you-like
#+end_src

Export with C-x v t. If you use noweb, orgmode will repeat the prefix for all the lines in the sub-block.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.