emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Support for whitespace prefix for :noweb-prefix
@ 2024-03-26 12:44 Doerthous
  2024-03-28 19:25 ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Doerthous @ 2024-03-26 12:44 UTC (permalink / raw)
  To: emacs-orgmode

Hi

Can we add a support for whitespace prefix such that the prefix of a
noweb-ref replaced by whitespace characters?

Here is a use case,

#+begin_src elisp :noweb-ref varable-bindings
(a 0)
(b 1)
#+end_src

#+begin_src elisp :noweb-ref do-something
`(,a ,b)
#+end_src

#+name: a-fragment
#+begin_src elisp :noweb yes :noweb-prefix whitespace
  (let (<<varable-bindings>>)
    <<do-something>>)
#+end_src

using whitespace :noweb-prefix, the above code will expand to

#+begin_src elisp
(let ((a 0)
      (b 1))
  `(,a ,b))
#+end_src

Best regards,

D


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-26 12:44 Support for whitespace prefix for :noweb-prefix Doerthous
@ 2024-03-28 19:25 ` Ihor Radchenko
  2024-03-29  2:55   ` Doerthous
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-03-28 19:25 UTC (permalink / raw)
  To: Doerthous; +Cc: emacs-orgmode

Doerthous <doerthous@gmail.com> writes:

> Can we add a support for whitespace prefix such that the prefix of a
> noweb-ref replaced by whitespace characters?
>
> ...
> #+name: a-fragment
> #+begin_src elisp :noweb yes :noweb-prefix whitespace
>   (let (<<varable-bindings>>)
>     <<do-something>>)
> #+end_src
>
> using whitespace :noweb-prefix, the above code will expand to
>
> #+begin_src elisp
> (let ((a 0)
>       (b 1))
>   `(,a ,b))
> #+end_src

Do you mean that you want the code to be indented according to the major
mode rules?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-28 19:25 ` Ihor Radchenko
@ 2024-03-29  2:55   ` Doerthous
  2024-03-29  9:43     ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Doerthous @ 2024-03-29  2:55 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> 于2024年3月29日周五 03:25写道:
>
> Doerthous <doerthous@gmail.com> writes:
>
> > Can we add a support for whitespace prefix such that the prefix of a
> > noweb-ref replaced by whitespace characters?
> >
> > ...
> > #+name: a-fragment
> > #+begin_src elisp :noweb yes :noweb-prefix whitespace
> >   (let (<<varable-bindings>>)
> >     <<do-something>>)
> > #+end_src
> >
> > using whitespace :noweb-prefix, the above code will expand to
> >
> > #+begin_src elisp
> > (let ((a 0)
> >       (b 1))
> >   `(,a ,b))
> > #+end_src
>
> Do you mean that you want the code to be indented according to the major
> mode rules?
>

Why it relates to major mode,

Currently, with :noweb-prefix set to yes, the above code will be expand to
#+begin_src elisp
(let ((a 0)
(let ((b 1))
   `(,a ,b))
#+end_src

~(let (~ is the prefix of <<varable-bindings>>.

I thought we can replace just the prefix in current code[1]  with
~(setq prefix (replace-regexp-in-string "[^ \t]" " " prefix))~ ?

[1] lisp/ob-core.el (org-babel-expand-noweb-references) @ 9.6.23


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29  2:55   ` Doerthous
@ 2024-03-29  9:43     ` Ihor Radchenko
  2024-03-29 12:47       ` Doerthous
  2024-04-03 12:27       ` Fraga, Eric
  0 siblings, 2 replies; 12+ messages in thread
From: Ihor Radchenko @ 2024-03-29  9:43 UTC (permalink / raw)
  To: Doerthous; +Cc: emacs-orgmode, Sébastien Miquel

Doerthous <doerthous@gmail.com> writes:

>> Do you mean that you want the code to be indented according to the major
>> mode rules?
>>
>
> Why it relates to major mode,
>
> Currently, with :noweb-prefix set to yes, the above code will be expand to
> #+begin_src elisp
> (let ((a 0)
> (let ((b 1))
>    `(,a ,b))
> #+end_src
>
> ~(let (~ is the prefix of <<varable-bindings>>.
>
> I thought we can replace just the prefix in current code[1]  with
> ~(setq prefix (replace-regexp-in-string "[^ \t]" " " prefix))~ ?

I see.
So, you want a custom prefix before the expanded noweb reference lines.

I think that a more general approach could be allowing :noweb-prefix to
have a value of string that will be appended to each line on the
expansion.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29  9:43     ` Ihor Radchenko
@ 2024-03-29 12:47       ` Doerthous
  2024-03-29 12:51         ` Ihor Radchenko
  2024-04-03 12:27       ` Fraga, Eric
  1 sibling, 1 reply; 12+ messages in thread
From: Doerthous @ 2024-03-29 12:47 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Sébastien Miquel

Ihor Radchenko <yantar92@posteo.net> writes:

> I think that a more general approach could be allowing :noweb-prefix to
> have a value of string that will be appended to each line on the
> expansion.

With the use case discussed before, is allowing :noweb-prefix to have a
value of string means I need to provide a string with 5 space
characters to :noweb-ref like this?

#+begin_src elisp :noweb yes :noweb-prefix "     "
  (let (<<varable-bindings>>)
    <<do-something>>)
#+end_src

Or is it some other way?


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29 12:47       ` Doerthous
@ 2024-03-29 12:51         ` Ihor Radchenko
  2024-03-29 13:30           ` Doerthous
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-03-29 12:51 UTC (permalink / raw)
  To: Doerthous; +Cc: emacs-orgmode, Sébastien Miquel

Doerthous <doerthous@gmail.com> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> I think that a more general approach could be allowing :noweb-prefix to
>> have a value of string that will be appended to each line on the
>> expansion.
>
> With the use case discussed before, is allowing :noweb-prefix to have a
> value of string means I need to provide a string with 5 space
> characters to :noweb-ref like this?

> #+begin_src elisp :noweb yes :noweb-prefix "     "
>   (let (<<varable-bindings>>)
>     <<do-something>>)
> #+end_src

Yes.

I still feel that what you are really looking for is major-mode-specific
indentation, not a prefix. Because indentation may require tabs, not
spaces. Or may interfere with programming language.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29 12:51         ` Ihor Radchenko
@ 2024-03-29 13:30           ` Doerthous
  2024-03-29 13:42             ` Ihor Radchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Doerthous @ 2024-03-29 13:30 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Sébastien Miquel

Ihor Radchenko <yantar92@posteo.net> writes:

> I still feel that what you are really looking for is major-mode-specific
> indentation, not a prefix. Because indentation may require tabs, not
> spaces. Or may interfere with programming language.

I kind of understand what you mean: what I need is just the no
option, after the expansion (maybe with the help of some
after-expansion-hooks), indent the source block according to
major-mode. Right?

I will try to find some hooks after expansion and some APIs to
indent a source block?

Are the any tips for doing this? :-)

Thanks in advance.


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29 13:30           ` Doerthous
@ 2024-03-29 13:42             ` Ihor Radchenko
  2024-03-29 14:01               ` Doerthous
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-03-29 13:42 UTC (permalink / raw)
  To: Doerthous; +Cc: emacs-orgmode, Sébastien Miquel

Doerthous <doerthous@gmail.com> writes:

> I kind of understand what you mean: what I need is just the no
> option, after the expansion (maybe with the help of some
> after-expansion-hooks), indent the source block according to
> major-mode. Right?
>
> I will try to find some hooks after expansion and some APIs to
> indent a source block?
>
> Are the any tips for doing this? :-)

Maybe `org-babel-tangle-body-hook'. If your problem is how the tangled
code looks like.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29 13:42             ` Ihor Radchenko
@ 2024-03-29 14:01               ` Doerthous
  0 siblings, 0 replies; 12+ messages in thread
From: Doerthous @ 2024-03-29 14:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode, Sébastien Miquel

Thanks, I'll check it out.


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-03-29  9:43     ` Ihor Radchenko
  2024-03-29 12:47       ` Doerthous
@ 2024-04-03 12:27       ` Fraga, Eric
  2024-04-03 13:01         ` Ihor Radchenko
  1 sibling, 1 reply; 12+ messages in thread
From: Fraga, Eric @ 2024-04-03 12:27 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Doerthous, emacs-orgmode@gnu.org, Sébastien Miquel

On Friday, 29 Mar 2024 at 09:43, Ihor Radchenko wrote:
> Doerthous <doerthous@gmail.com> writes:
>> #+begin_src elisp
>> (let ((a 0)
>> (let ((b 1))
>>    `(,a ,b))
>> #+end_src
>>
>> ~(let (~ is the prefix of <<varable-bindings>>.
>>
>> I thought we can replace just the prefix in current code[1]  with
>> ~(setq prefix (replace-regexp-in-string "[^ \t]" " " prefix))~ ?
>
> I see.
> So, you want a custom prefix before the expanded noweb reference lines.

Not only that; at the moment, the prefix is defined by the text that
comes before the noweb reference and hence why the "(let (" is repeated
on the second line in the code block above.

So it's a combination of no prefix in such a case and the indentation
according to major mode.  For me, the latter is not an issue but the
former is.

(but not really an issue for me as I make sure I only have noweb
references on lines where such a replacement will not cause any
problems...)

-- 
: Eric S Fraga, with org release_9.6.23-1314-g945046 in Emacs 30.0.50

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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-04-03 12:27       ` Fraga, Eric
@ 2024-04-03 13:01         ` Ihor Radchenko
  2024-04-03 13:25           ` Fraga, Eric
  0 siblings, 1 reply; 12+ messages in thread
From: Ihor Radchenko @ 2024-04-03 13:01 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Doerthous, emacs-orgmode@gnu.org, Sébastien Miquel

"Fraga, Eric" <e.fraga@ucl.ac.uk> writes:

> So it's a combination of no prefix in such a case and the indentation
> according to major mode.  For me, the latter is not an issue but the
> former is.
>
> (but not really an issue for me as I make sure I only have noweb
> references on lines where such a replacement will not cause any
> problems...)

You can just use :noweb-prefix no. It is already a part of Org.
What we are discussing is adding more functionality to this new
parameter.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: Support for whitespace prefix for :noweb-prefix
  2024-04-03 13:01         ` Ihor Radchenko
@ 2024-04-03 13:25           ` Fraga, Eric
  0 siblings, 0 replies; 12+ messages in thread
From: Fraga, Eric @ 2024-04-03 13:25 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Doerthous, emacs-orgmode@gnu.org, Sébastien Miquel

Ah, okay.  Thank you.
-- 
: Eric S Fraga, with org release_9.6.23-1314-g945046 in Emacs 30.0.50

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

end of thread, other threads:[~2024-04-03 13:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-26 12:44 Support for whitespace prefix for :noweb-prefix Doerthous
2024-03-28 19:25 ` Ihor Radchenko
2024-03-29  2:55   ` Doerthous
2024-03-29  9:43     ` Ihor Radchenko
2024-03-29 12:47       ` Doerthous
2024-03-29 12:51         ` Ihor Radchenko
2024-03-29 13:30           ` Doerthous
2024-03-29 13:42             ` Ihor Radchenko
2024-03-29 14:01               ` Doerthous
2024-04-03 12:27       ` Fraga, Eric
2024-04-03 13:01         ` Ihor Radchenko
2024-04-03 13:25           ` Fraga, Eric

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