Fork me on GitHub
#emacs
<
2022-07-28
>
Benjamin09:07:39

Consider this org src block

#+begin_src clojure
(with-out-str (pp/print-table [{:foo 10} {:foo  11}]))
#+end_src

#+RESULTS:
: \n| :foo |\n|------|\n|   10 |\n|   11 |\n
any ideas how to insert the string as text, instead of string?

Benjamin09:07:37

after checking ob-clojure.el I determined that

#+begin_src clojure :results  pp
(pp/print-table [{:foo 10} {:foo  11}])
#+end_src
automatically does what I want. It takes out from the nrepl result instead of value. I was considering to add pp-table next to pp because I am abusing the pp a bit and still need the print-table call in the code, but whatever.

teodorlu09:07:19

Mind pasting in the output you got? I've been occasionally frustrated when org tries to interpret everything as a table myself.

Benjamin09:07:17

#+begin_src clojure :results  pp
(pp/print-table [{:foo 10} {:foo  11}])
#+end_src

#+RESULTS:
: 
: | :foo |
: |------|
: |   10 |
: |   11 |
: 
: 

👍 1
Benjamin09:07:30

I'm not sure what's up with : Also there is 1 extra blank line because it says "pp nil" once because of the hack

👍 1
Benjamin11:07:23

#+begin_src clojure :results  pp table
(pp/print-table [{:foo 10} {:foo  11}])
#+end_src

#+RESULTS:
| :foo |
|------|
|   10 |
|   11 |
now it is a true org table

teodorlu11:07:04

Ohhh, nice! Gonna steal that one 😊😁

teodorlu11:07:25

Do your clojure blocks run against a persistent process (REPL)? I'm curious if it would be possible to execute stuff like that with babashka.

Benjamin12:07:24

proof of concept:

#+begin_src elisp
(defun org-babel-execute:bb (s params)
  "Execute `S` with babashka."
  (shell-command-to-string (format "bb -e '%s'" s)))

(add-to-list 'org-src-lang-modes '("bb" . clojure))
#+end_src

#+begin_src bb
  (+ 1 2 3)
#+end_src

#+RESULTS:
: 6

Benjamin12:07:40

extending ob-clojure is maybe the right way though

teodorlu15:07:41

Oh, cool! 😎

pesterhazy17:07:03

Hey, question not related to Clojure I've been using expand-region (best way to select stuff, period), but since upgrading to 28.1, when I run

M-x er/expand-region

pesterhazy17:07:24

I get this error

Wrong type argument: stringp, (require . diff)

pesterhazy17:07:01

Any ideas what could be wrong, or how I could debug this? BTW try out expand-region, it lets you start with a word and then move up to form, enclosing form, function etc, all interactively https://github.com/magnars/expand-region.el

pesterhazy17:07:58

(PS, maybe this is to do with some other package I have installed?)

pesterhazy17:07:18

Huh, after re-installing the package, now I get a different message:

Wrong type argument: stringp, (require . package)

apt17:07:28

You can toggle-debug-on-error and check what’s the problematic line

pesterhazy18:07:07

let me see...

pesterhazy18:07:10

Debugger entered--Lisp error: (wrong-type-argument stringp (require . package))
  string-match("\\(\\`\\|/\\)text-mode\\(\\.so\\|\\.dylib\\|\\.elc\\|\\.el\\)?\\..." (require . package))
  load-history-filename-element("\\(\\`\\|/\\)text-mode\\(\\.so\\|\\.dylib\\|\\.elc\\|\\.el\\)?\\...")
  eval-after-load("text-mode" #f(compiled-function () #<bytecode 0x1fc49373f5612>))
  byte-code("\300\301\302\"\210\300\303\304\"\210\300\305\306\"\210\300\307\310\"\210\300\311\312\"\210\300\313\314\"\210\300\315\316\"\210\300\317\320\"\210\300\321\322\"\210\300\323\324\"\210..." [eval-after-load clojure-mode #f(compiled-function () #<bytecode 0x1fc4934087f72>) css-mode #f(compiled-function () #<bytecode 0x1fc4934084cd2>) erlang-mode #f(compiled-function () #<bytecode 0x1fc49333ef98e>) feature-mode #f(compiled-function () #<bytecode 0x1fc4933291926>) sgml-mode #f(compiled-function () #<bytecode 0x1fc4933291872>) rhtml-mode #f(compiled-function () #<bytecode 0x1fc4933291872>) nxhtml-mode #f(compiled-function () #<bytecode 0x1fc4933291872>) web-mode #f(compiled-function () #<bytecode 0x1fc4933290c0a>) js #f(compiled-function () #<bytecode 0x1fc4933290dd6>) js2-mode #f(compiled-function () #<bytecode 0x1fc4933290dd6>) #f(compiled-function () #<bytecode 0x1fc4933290ba2>) js3-mode #f(compiled-function () #<bytecode 0x1fc4933290dd6>) latex #f(compiled-function () #<bytecode 0x1fc4933290b6e>) nxml-mode #f(compiled-function () #<bytecode 0x1fc4933290a3a>) octave-mod #f(compiled-function () #<bytecode 0x1fc49332909d2>) octave #f(compiled-function () #<bytecode 0x1fc49332909d2>) python #f(compiled-function () #<bytecode -0xbcec82b8f601688>) python-mode #f(compiled-function () #<bytecode 0x1fc49332938b6>) ruby-mode #f(compiled-function () #<bytecode 0x1fc4934084a6a>) org #f(compiled-function () #<bytecode 0x1fc4933290102>) cc-mode #f(compiled-function () #<bytecode 0x1fc4934087cde>) "text-mode" #f(compiled-function () #<bytecode 0x1fc49373f5612>) cperl-mode #f(compiled-function () #<bytecode 0x1fc493408786e>) sml-mode #f(compiled-function () #<bytecode 0x1fc49373f56de>) enh-ruby-mode #f(compiled-function () #<bytecode 0x1fc49333eca12>) ...] 3)
  autoload-do-load((autoload "expand-region" "Increase selected region by semantic units.\n\nWith ..." t nil) er/expand-region)
  command-execute(er/expand-region)

apt18:07:46

It seems that require expected a string (as usual), but it got other thing. Maybe try to bisect your config. For example, try using emacs -q and loading only expand-region.

pesterhazy18:07:09

The way I read it the problem is with string-match, not require

apt18:07:40

Ah, yeah, maybe. It’s a bit hard to read 😅

pesterhazy18:07:18

bisecting the init.el is a good idea

pesterhazy18:07:17

hm, I don't even know how to require the package

pesterhazy18:07:21

ah I figured it out

pesterhazy18:07:33

M-x package-initialize

pesterhazy18:07:07

and sure enough it works with only expand-region loaded

pesterhazy18:07:20

so now I have to really bisect the init.el I guess?

apt18:07:48

I’d recommend that, yeap

pesterhazy18:07:37

ok so this is strange with emacs -q it works without -q but with an init.el that only contains (package-initialize) I get the error message

pesterhazy18:07:57

better yet: emacs -q: works emacs with empty init.el: doesn't work

pesterhazy18:07:07

shouldn't those two be identical?

apt18:07:04

yeah. strange. not sure what’s going on. maybe wipe out your elpa folder and reinstall all packages (you can backup the current emacs.d first, just in case)

pesterhazy21:07:30

Ok so after much digging I found that the offending line is this https://github.com/magnars/expand-region.el/blob/master/expand-region.el#L188

pesterhazy21:07:08

all other calls to eval-after-load take a symbol, but this one takes "text-mode" as a string

pesterhazy21:07:26

from what I can tell, that odd call (introduced in this pr https://github.com/magnars/expand-region.el/pull/213) seems to break with Emacs 28

pesterhazy21:07:46

Thanks for the help @U976F1AR2

apt21:07:45

cool, I’m glad you found the issue

apt21:07:26

I confess I found it surprising that more users didn’t report it (I suppose), though – AFAIK expand-region is widely used :thinking_face:

pesterhazy22:07:07

Well, expand-region doesn't accept bug reports anymore, so people don't have a venue where they can report issues

pesterhazy22:07:36

(But I may also be wrong about this, as I know very little about elisp)

apt12:07:02

> Well, expand-region doesn’t accept bug reports anymore, so people don’t have a venue where they can report issues Oh, got it.

apt12:07:13

Makes sense, yeah

pesterhazy17:07:37

How do I get a backtrace for an error like this?

apt18:07:09

I think it was supposed to be there, isn’t it?

pesterhazy18:07:29

yup you answered in the other thread