1

I have a list of more than 80 search engines to perform keyword searches. They are listed in an org-table like this:

#+name: keyword-search
|---------------+---------------------------------------------------------------------+-----|
| Name          | URL                                                                 | key |
|---------------+---------------------------------------------------------------------+-----|
| Antonyms-PT   | https://www.powerthesaurus.org/%s/antonyms                          | eta |
| Arch-Packages | https://archlinux.org/packages/?sort=&q=%s                          | pac |
| Arch-Wiki     | https://wiki.archlinux.org/index.php?title=Special:Search&search=%s | wia |
| IMDB          | http://www.imdb.com/find?s=all&q=%s                                 | imd |
| Synonyms-WR   | https://www.wordreference.com/synonyms/%s                           | ets |
| ...           | ...                                                                 | ... |
|---------------+---------------------------------------------------------------------+-----|

I would like to generate defengine macros (which are used by engine-mode) from this table. The output would look like this:

(defengine Antonyms-PT "https://www.powerthesaurus.org/%s/antonyms" :keybinding "eta")
(defengine Arch-Packages "https://archlinux.org/packages/?sort=&q=%s" :keybinding "pac")
(defengine WikiArch "https://wiki.archlinux.org/index.php?title=Special:Search&search=%s" :keybinding "wia")
(defengine IMDB "http://www.imdb.com/find?s=all&q=%s" :keybinding "imd")  
(defengine Synonyms-WR "https://www.wordreference.com/synonyms/%s" :keybinding "ets")

What are the Elisp tools that I could use to write such a script?

crocefisso
  • 1,141
  • 7
  • 15

1 Answers1

1

You can write a script (in any language) that takes the table as input and produces your desired output and put it in an Org Babel source block. E.g. here's a python script:

#+name: keyword-search
|---------------+---------------------------------------------------------------------+-----|
| Name          | URL                                                                 | key |
|---------------+---------------------------------------------------------------------+-----|
| Antonyms-PT   | https://www.powerthesaurus.org/%s/antonyms                          | eta |
| Arch-Packages | https://archlinux.org/packages/?sort=&q=%s                          | pac |
| Arch-Wiki     | https://wiki.archlinux.org/index.php?title=Special:Search&search=%s | wia |
| IMDB          | http://www.imdb.com/find?s=all&q=%s                                 | imd |
| Synonyms-WR   | https://www.wordreference.com/synonyms/%s                           | ets |


#+begin_src python :var tbl=keyword-search :results output drawer
  for row in tbl[1:]:
      print(f'(defengine {row[0]} "{row[1]}" :keybinding "{row[2]}")')
#+end_src

#+RESULTS:
:results:
(defengine Antonyms-PT "https://www.powerthesaurus.org/%s/antonyms" :keybinding "eta")
(defengine Arch-Packages "https://archlinux.org/packages/?sort=&q=%s" :keybinding "pac")
(defengine Arch-Wiki "https://wiki.archlinux.org/index.php?title=Special:Search&search=%s" :keybinding "wia")
(defengine IMDB "http://www.imdb.com/find?s=all&q=%s" :keybinding "imd")
(defengine Synonyms-WR "https://www.wordreference.com/synonyms/%s" :keybinding "ets")
:end:

Python is convenient here, but you could use elisp or really any other language to do it.

NickD
  • 27,023
  • 3
  • 23
  • 42