* export code with backslashes
@ 2015-03-16 15:47 hymie!
2015-03-16 22:28 ` Charles C. Berry
0 siblings, 1 reply; 5+ messages in thread
From: hymie! @ 2015-03-16 15:47 UTC (permalink / raw)
To: emacs-orgmode
Greetings.
I'm only asking this question because it seems that Orgmode can do
anything, although I admit that what I'm asking for is probably outside
the normal scope.
I have snips of code in my org files, denoted as ~code~. I prefer ~code~ to
BEGIN_SRC blocks, because I don't like the big grey text boxes in my
exported documents. Sometimes my code is very long and includes long lists
of options and arguments and such; for example:
~useradd -U -G wheel -p
'$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//'
accountname~
This is all one line.
Then I use C-c C-e t A to "export" this into an ascii buffer, the sole
reason being to remove the tilde characters and provide me an easy
cut-n-paste option. I end up with this:
useradd -U -G wheel -p <newline>
'$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//'
<newline>
accountname <newline>
I would really really really like it if, in addition to the newlines that
are added, a backslash could be added as well. "Hey, this is a line
enclosed in tildes. I'm going to add line-breaks. Each line-break except
for the one at the end needs a backslash"
useradd -U -G wheel -p \<newline>
'$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//' \<newline>
accountname <newline>
Is such a thing possible?
--hymie!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: export code with backslashes
2015-03-16 15:47 export code with backslashes hymie!
@ 2015-03-16 22:28 ` Charles C. Berry
2015-03-16 23:11 ` hymie
2015-03-18 13:09 ` hymie
0 siblings, 2 replies; 5+ messages in thread
From: Charles C. Berry @ 2015-03-16 22:28 UTC (permalink / raw)
To: hymie!; +Cc: emacs-orgmode
On Mon, 16 Mar 2015, hymie! wrote:
> Greetings.
>
> I'm only asking this question because it seems that Orgmode can do
> anything, although I admit that what I'm asking for is probably outside
> the normal scope.
>
> I have snips of code in my org files, denoted as ~code~. I prefer ~code~ to
> BEGIN_SRC blocks, because I don't like the big grey text boxes in my
> exported documents. Sometimes my code is very long and includes long lists
> of options and arguments and such; for example:
>
> ~useradd -U -G wheel -p
> '$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//'
> accountname~
>
> This is all one line.
>
> Then I use C-c C-e t A to "export" this into an ascii buffer, the sole
> reason being to remove the tilde characters and provide me an easy
> cut-n-paste option. I end up with this:
>
> useradd -U -G wheel -p <newline>
> '$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//'
> <newline>
> accountname <newline>
>
> I would really really really like it if, in addition to the newlines that
> are added, a backslash could be added as well. "Hey, this is a line
> enclosed in tildes. I'm going to add line-breaks. Each line-break except
> for the one at the end needs a backslash"
>
> useradd -U -G wheel -p \<newline>
> '$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//' \<newline>
> accountname <newline>
>
> Is such a thing possible?
Yes.
You can add a filter, see (info "(org) Advanced configuration")
The line breaks come _after_ the code is processed. So you need to make
the line breaks happen before you know can replace them. Try:
#+BEGIN_SRC emacs-lisp
(defun org-export-ascii-filter-code (text back-end info)
"Replace `\\n' with `\\' in ascii code."
(if (eq back-end 'ascii)
(replace-regexp-in-string
"\n" "\\\n"
(org-babel-chomp
(org-export-string-as text 'ascii t))
nil t)
text))
(add-to-list 'org-export-filter-code-functions
'org-export-ascii-filter-code)
#+END_SRC
with ascii export.
When I run this on your example, I get only one line break, but it is
preceeded by a backslash.
Naturally, you will need to adapt this up for other backends as a single
backslash might not be what is wanted.
HTH,
Chuck
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: export code with backslashes
2015-03-16 22:28 ` Charles C. Berry
@ 2015-03-16 23:11 ` hymie
2015-03-18 13:09 ` hymie
1 sibling, 0 replies; 5+ messages in thread
From: hymie @ 2015-03-16 23:11 UTC (permalink / raw)
To: Charles C. Berry; +Cc: emacs-orgmode
"Charles C. Berry" writes:
>On Mon, 16 Mar 2015, hymie! wrote:
>> useradd -U -G wheel -p \<newline>
>> '$6$wcMRrkcdGeNHLT5b$password0ISmGZSsILOyV/WJnpassword//' \<newline>
>> accountname <newline>
>>
>> Is such a thing possible?
>
>Yes.
>
>#+BEGIN_SRC emacs-lisp
> (defun org-export-ascii-filter-code (text back-end info)
> "Replace `\\n' with `\\' in ascii code."
> (if (eq back-end 'ascii)
> (replace-regexp-in-string
> "\n" "\\\n"
> (org-babel-chomp
> (org-export-string-as text 'ascii t))
> nil t)
> text))
> (add-to-list 'org-export-filter-code-functions
> 'org-export-ascii-filter-code)
>#+END_SRC
Awesome -- this is perfect. (Note that, to be perfect, the
continuation lines need at least one leading space.)
>When I run this on your example, I get only one line break, but it is
>preceeded by a backslash.
My original post had a much much longer password string, but the
web-to-news gateway demanded 80 characters or less, so I trimmed the
password but left in the line breaks.
>Naturally, you will need to adapt this up for other backends as a single
>backslash might not be what is wanted.
I hope my programming skills are up to the task. But it's certainly
a great jumping-off point.
Thank you.
--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
My fitbit says I've walked 7009 steps today (as of 19:02).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: export code with backslashes
2015-03-16 22:28 ` Charles C. Berry
2015-03-16 23:11 ` hymie
@ 2015-03-18 13:09 ` hymie
2015-03-18 17:10 ` Charles C. Berry
1 sibling, 1 reply; 5+ messages in thread
From: hymie @ 2015-03-18 13:09 UTC (permalink / raw)
To: Charles C. Berry; +Cc: emacs-orgmode
"Charles C. Berry" writes:
> (defun org-export-ascii-filter-code (text back-end info)
> "Replace `\\n' with `\\' in ascii code."
> (if (eq back-end 'ascii)
> (replace-regexp-in-string
> "\n" "\\\n"
> (org-babel-chomp
> (org-export-string-as text 'ascii t))
> nil t)
> text))
> (add-to-list 'org-export-filter-code-functions
> 'org-export-ascii-filter-code)
Just for the record.....
I had an open running emacs. I changed my .emacs file, applied the change
with M-x load-file .emacs , and it worked perfectly.
But today, I opened emacs fresh, and was greeted with an error
Symbol's value as variable is void: org-export-filter-code-functions
I got the same error when I tried to M-x load-file .emacs
But
After I did an ascii export (in which the backslashes do not appear), I could
then M-x load-file .emacs, no error, and the backslashes worked.
I added
(require 'ox)
to my .emacs file, and that resolved the problem.
This error only happens on my Windows machine. On my Unix machine, it
appears to work correctly the first time, and I do not see any differences
between the .emacs files on the two machines.
--hymie! http://lactose.homelinux.net/~hymie hymie@lactose.homelinux.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: export code with backslashes
2015-03-18 13:09 ` hymie
@ 2015-03-18 17:10 ` Charles C. Berry
0 siblings, 0 replies; 5+ messages in thread
From: Charles C. Berry @ 2015-03-18 17:10 UTC (permalink / raw)
To: hymie; +Cc: emacs-orgmode
On Wed, 18 Mar 2015, hymie@lactose.homelinux.net wrote:
> "Charles C. Berry" writes:
>> (defun org-export-ascii-filter-code (text back-end info)
>> "Replace `\\n' with `\\' in ascii code."
>> (if (eq back-end 'ascii)
>> (replace-regexp-in-string
>> "\n" "\\\n"
>> (org-babel-chomp
>> (org-export-string-as text 'ascii t))
>> nil t)
>> text))
>> (add-to-list 'org-export-filter-code-functions
>> 'org-export-ascii-filter-code)
>
> Just for the record.....
>
> I had an open running emacs. I changed my .emacs file, applied the change
> with M-x load-file .emacs , and it worked perfectly.
>
> But today, I opened emacs fresh, and was greeted with an error
>
> Symbol's value as variable is void: org-export-filter-code-functions
>
> I got the same error when I tried to M-x load-file .emacs
>
> But
>
> After I did an ascii export (in which the backslashes do not appear), I could
> then M-x load-file .emacs, no error, and the backslashes worked.
>
> I added
> (require 'ox)
> to my .emacs file, and that resolved the problem.
>
Use
#+BEGIN_SRC emacs-lisp
(eval-after-load 'ox
'(add-to-list
'org-export-filter-code-functions
'org-export-ascii-filter-code))
#+END_SRC
Chuck
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-18 17:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-16 15:47 export code with backslashes hymie!
2015-03-16 22:28 ` Charles C. Berry
2015-03-16 23:11 ` hymie
2015-03-18 13:09 ` hymie
2015-03-18 17:10 ` Charles C. Berry
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).