emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* how to remove parentheses from the output of a source code block
@ 2022-09-28  3:17 Andrés Ramírez
  2022-09-28  4:01 ` Greg Minshall
  0 siblings, 1 reply; 4+ messages in thread
From: Andrés Ramírez @ 2022-09-28  3:17 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

I have this file:
--8<---------------cut here---------------start------------->8---
* labels table
** work on this file then move the output to the required buffers
#+name: source-in-table
| ID | MACRO_SRC_CODE_HEADER | LANGUAGE1_HEADER | LANGUAGE2_HEADER |
|----+-----------------------+------------------+------------------|
|  1 | LABEL_YES             | Si               | Yes              |
|  2 | LABEL_NO              | No               | No               |
** generate sql
#+BEGIN_SRC emacs-lisp :var table=source-in-table :results value raw
  (let ((sqlcode (mapcar (lambda (row) 
                           (concat "INSERT or ignore INTO labels_catalog (id, macro, language1, language2) VALUES ("
                                   (number-to-string (nth 0 row)) ", '" (nth 1 row) "', '" (nth 2 row) "', '"
                                   (nth 3 row) "');\n")
                           ) table)))
    sqlcode)
#+END_SRC
--8<---------------cut here---------------end--------------->8---

The above file generates this output:
--8<---------------cut here---------------start------------->8---
#+RESULTS:
(INSERT or ignore INTO labels_catalog (id, macro, language1, language2) VALUES (1, 'LABEL_YES', 'Si', 'Yes');
 INSERT or ignore INTO labels_catalog (id, macro, language1, language2) VALUES (2, 'LABEL_NO', 'No', 'No');
)
--8<---------------cut here---------------end--------------->8---

How could be removed the parentheses from the output?

Best Regards


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to remove parentheses from the output of a source code block
  2022-09-28  3:17 how to remove parentheses from the output of a source code block Andrés Ramírez
@ 2022-09-28  4:01 ` Greg Minshall
  2022-09-28  6:42   ` Greg Minshall
  2022-09-29 17:52   ` andrés ramírez
  0 siblings, 2 replies; 4+ messages in thread
From: Greg Minshall @ 2022-09-28  4:01 UTC (permalink / raw)
  To: =?utf-8?Q?Andr=C3=A9s_Ram=C3=ADrez?=; +Cc: emacs-orgmode

Andrés,

this is maybe more of an e-lisp question, or, at least, here's more of
an e-lisp answer.  if you have the useful =s= package [1] installed,
then will using =s-join= give you what you want?
----
  (let ((sqlcode (mapcar (lambda (row) 
                           (concat "INSERT or ignore INTO labels_catalog (id, macro, language1, language2) VALUES ("
                                   (number-to-string (nth 0 row)) ", '" (nth 1 row) "', '" (nth 2 row) "', '"
                                   (nth 3 row) "');\n")
                           ) table)))
    (s-join " " sqlcode))
----
give you what you are looking for?

cheers, Greg

[1] https://github.com/magnars/s.el


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to remove parentheses from the output of a source code block
  2022-09-28  4:01 ` Greg Minshall
@ 2022-09-28  6:42   ` Greg Minshall
  2022-09-29 17:52   ` andrés ramírez
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Minshall @ 2022-09-28  6:42 UTC (permalink / raw)
  Cc: =?us-ascii?Q?=3D=3Futf-8=3FQ=3FAndr=3DC3=3DA9s=5FRam=3DC3=3DADrez=3F?= =?us-ascii?Q?=3D?=,
	emacs-orgmode

Andrés,

sorry -- of course, you can use base e-lisp =string-join= to accomplish
the same thing.
----
#+BEGIN_SRC emacs-lisp :var table=source-in-table :results value raw
  (let ((sqlcode (mapcar (lambda (row) 
                           (concat "INSERT or ignore INTO labels_catalog (id, macro, language1, language2) VALUES ("
                                   (number-to-string (nth 0 row)) ", '" (nth 1 row) "', '" (nth 2 row) "', '"
                                   (nth 3 row) "');\n")
                           ) table)))
    (string-join sqlcode " "))
#+END_SRC
----

cheers, Greg


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to remove parentheses from the output of a source code block
  2022-09-28  4:01 ` Greg Minshall
  2022-09-28  6:42   ` Greg Minshall
@ 2022-09-29 17:52   ` andrés ramírez
  1 sibling, 0 replies; 4+ messages in thread
From: andrés ramírez @ 2022-09-29 17:52 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Hi. Greg.

>>>>> "Greg" == Greg Minshall <minshall@umich.edu> writes:

    Greg> Andrés, this is maybe more of an e-lisp question, or, at least, here's more of an e-lisp
    Greg> answer.  if you have the useful =s= package [1] installed, then will using =s-join= give
    Greg> you what you want?  

[...]

Yest that elisp snippet help me. And It gave me what I was looking
for. I just did:
s/(s-join " " sqlcode)/(with-temp-buffer (insert (format "%s" sqlcode)) (delete-rectangle (point-min) (point-max)) (buffer-string))/

Best Regards


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-29 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  3:17 how to remove parentheses from the output of a source code block Andrés Ramírez
2022-09-28  4:01 ` Greg Minshall
2022-09-28  6:42   ` Greg Minshall
2022-09-29 17:52   ` andrés ramírez

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).