all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Enclosing text in a box
@ 2022-11-16 12:47 Heime
  2022-11-16 13:07 ` Heime
  2022-11-17  6:43 ` Jean Louis
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-11-16 12:47 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


Would like to enclose some text in a box?  The box has to automatically adjust its size
according to the size of the text.

      (insert "╔══════╗\n")
      (insert (concat "║" text "║\n" ))
      (insert "╚══════╝" )





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

* Re: Enclosing text in a box
  2022-11-16 12:47 Enclosing text in a box Heime
@ 2022-11-16 13:07 ` Heime
  2022-11-16 13:34   ` Alexis Roda
  2022-11-17  6:43 ` Jean Louis
  1 sibling, 1 reply; 32+ messages in thread
From: Heime @ 2022-11-16 13:07 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor


------- Original Message -------
On Wednesday, November 16th, 2022 at 12:47 PM, Heime <heimeborgia@protonmail.com> wrote:


> Would like to enclose some text in a box? The box has to automatically adjust its size
> according to the size of the text.
> 
> (insert "╔══════╗\n")
> (insert (concat "║" text "║\n" ))
> (insert "╚══════╝" )

Is there a repeat character in elisp?

Then I could do 

(repeat-string (length text) "═")






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

* Re: Enclosing text in a box
  2022-11-16 13:07 ` Heime
@ 2022-11-16 13:34   ` Alexis Roda
  2022-11-16 13:58     ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Alexis Roda @ 2022-11-16 13:34 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

You were almost there, (make-string (length text") ?=)

https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html

Missatge de Heime <heimeborgia@protonmail.com> del dia dc., 16 de nov. 2022
a les 14:09:

>
> ------- Original Message -------
> On Wednesday, November 16th, 2022 at 12:47 PM, Heime <
> heimeborgia@protonmail.com> wrote:
>
>
> > Would like to enclose some text in a box? The box has to automatically
> adjust its size
> > according to the size of the text.
> >
> > (insert "╔══════╗\n")
> > (insert (concat "║" text "║\n" ))
> > (insert "╚══════╝" )
>
> Is there a repeat character in elisp?
>
> Then I could do
>
> (repeat-string (length text) "═")
>
>
>
>
>


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

* Re: Enclosing text in a box
  2022-11-16 13:34   ` Alexis Roda
@ 2022-11-16 13:58     ` Eli Zaretskii
  2022-11-16 14:11       ` Yuri Khan
  0 siblings, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-16 13:58 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Alexis Roda <alexis.roda.villalonga@gmail.com>
> Date: Wed, 16 Nov 2022 14:34:09 +0100
> Cc: Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> You were almost there, (make-string (length text") ?=)

Using 'length' to measure the width of text on display is not
reliable, because there are characters of different width.  It is
better to use 'string-width' or 'string-pixel-width' instead.



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

* Re: Enclosing text in a box
  2022-11-16 13:58     ` Eli Zaretskii
@ 2022-11-16 14:11       ` Yuri Khan
  2022-11-16 14:20         ` Heime
  2022-11-16 14:47         ` Eli Zaretskii
  0 siblings, 2 replies; 32+ messages in thread
From: Yuri Khan @ 2022-11-16 14:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 16 Nov 2022 at 20:59, Eli Zaretskii <eliz@gnu.org> wrote:

> Using 'length' to measure the width of text on display is not
> reliable, because there are characters of different width.  It is
> better to use 'string-width' or 'string-pixel-width' instead.

The next stumbling point is going to be “make-string does the wrong
thing when passed 17.237 as the count”, without an explanation as to
what the right thing would be. (I don’t know either.)



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

* Re: Enclosing text in a box
  2022-11-16 14:11       ` Yuri Khan
@ 2022-11-16 14:20         ` Heime
  2022-11-16 14:47         ` Eli Zaretskii
  1 sibling, 0 replies; 32+ messages in thread
From: Heime @ 2022-11-16 14:20 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Eli Zaretskii, help-gnu-emacs

------- Original Message -------
On Wednesday, November 16th, 2022 at 2:11 PM, Yuri Khan <yuri.v.khan@gmail.com> wrote:


> On Wed, 16 Nov 2022 at 20:59, Eli Zaretskii eliz@gnu.org wrote:
> 
> > Using 'length' to measure the width of text on display is not
> > reliable, because there are characters of different width. It is
> > better to use 'string-width' or 'string-pixel-width' instead.
> 
> 
> The next stumbling point is going to be “make-string does the wrong
> thing when passed 17.237 as the count”, without an explanation as to
> what the right thing would be. (I don’t know either.)

Emacs should have the right amount of space to insert the printing entity. 




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

* Re: Enclosing text in a box
  2022-11-16 14:11       ` Yuri Khan
  2022-11-16 14:20         ` Heime
@ 2022-11-16 14:47         ` Eli Zaretskii
  2022-11-16 14:51           ` Heime
  2022-11-16 14:55           ` Yuri Khan
  1 sibling, 2 replies; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-16 14:47 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Wed, 16 Nov 2022 21:11:04 +0700
> Cc: help-gnu-emacs@gnu.org
> 
> On Wed, 16 Nov 2022 at 20:59, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> > Using 'length' to measure the width of text on display is not
> > reliable, because there are characters of different width.  It is
> > better to use 'string-width' or 'string-pixel-width' instead.
> 
> The next stumbling point is going to be “make-string does the wrong
> thing when passed 17.237 as the count”, without an explanation as to
> what the right thing would be. (I don’t know either.)

Why would sane code call make-string with such an argument?



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

* Re: Enclosing text in a box
  2022-11-16 14:47         ` Eli Zaretskii
@ 2022-11-16 14:51           ` Heime
  2022-11-16 14:55             ` Emanuel Berg
  2022-11-16 16:44             ` Eli Zaretskii
  2022-11-16 14:55           ` Yuri Khan
  1 sibling, 2 replies; 32+ messages in thread
From: Heime @ 2022-11-16 14:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


------- Original Message -------
On Wednesday, November 16th, 2022 at 2:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > From: Yuri Khan yuri.v.khan@gmail.com
> > Date: Wed, 16 Nov 2022 21:11:04 +0700
> > Cc: help-gnu-emacs@gnu.org
> > 
> > On Wed, 16 Nov 2022 at 20:59, Eli Zaretskii eliz@gnu.org wrote:
> > 
> > > Using 'length' to measure the width of text on display is not
> > > reliable, because there are characters of different width. It is
> > > better to use 'string-width' or 'string-pixel-width' instead.
> > 
> > The next stumbling point is going to be “make-string does the wrong
> > thing when passed 17.237 as the count”, without an explanation as to
> > what the right thing would be. (I don’t know either.)
> 
> 
> Why would sane code call make-string with such an argument?

The premise seems to be that "string-width" returns it.  I would like to
have the ability to pass unicode characters.



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

* Re: Enclosing text in a box
  2022-11-16 14:47         ` Eli Zaretskii
  2022-11-16 14:51           ` Heime
@ 2022-11-16 14:55           ` Yuri Khan
  2022-11-16 15:06             ` Yuri Khan
  1 sibling, 1 reply; 32+ messages in thread
From: Yuri Khan @ 2022-11-16 14:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 16 Nov 2022 at 21:48, Eli Zaretskii <eliz@gnu.org> wrote:

> > > Using 'length' to measure the width of text on display is not
> > > reliable, because there are characters of different width.  It is
> > > better to use 'string-width' or 'string-pixel-width' instead.
> >
> > The next stumbling point is going to be “make-string does the wrong
> > thing when passed 17.237 as the count”, without an explanation as to
> > what the right thing would be. (I don’t know either.)
>
> Why would sane code call make-string with such an argument?

My train of thought was:

* OP uses ‘length’ to measure the text, and ‘make-string’ to build a box.
* You point out that this fails for non-monospace fonts, and suggest
measuring with ‘string-width’ or ‘string-pixel-width’.
* OP tries to measure in pixels, realizes one has to divide by the
width of a box drawing character. The division result turns out
fractional.



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

* Re: Enclosing text in a box
  2022-11-16 14:51           ` Heime
@ 2022-11-16 14:55             ` Emanuel Berg
  2022-11-16 20:56               ` Emanuel Berg
  2022-11-16 16:44             ` Eli Zaretskii
  1 sibling, 1 reply; 32+ messages in thread
From: Emanuel Berg @ 2022-11-16 14:55 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

> The premise seems to be that "string-width" returns it.
> I would like to have the ability to pass unicode characters.

Didn't Jean do exactly this very recently on gmane.emacs.help ?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 14:55           ` Yuri Khan
@ 2022-11-16 15:06             ` Yuri Khan
  2022-11-16 16:12               ` tomas
  0 siblings, 1 reply; 32+ messages in thread
From: Yuri Khan @ 2022-11-16 15:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 16 Nov 2022 at 21:55, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> * OP uses ‘length’ to measure the text, and ‘make-string’ to build a box.
> * You point out that this fails for non-monospace fonts, and suggest
> measuring with ‘string-width’ or ‘string-pixel-width’.
> * OP tries to measure in pixels, realizes one has to divide by the
> width of a box drawing character. The division result turns out
> fractional.

A more-or-less complete solution would probably involve:

* Measuring pixel width of the enclosed text.
* Measuring pixel width of the box drawing character.
* Dividing one by the other, rounding up.
* Appending to the enclosed text a space with a display property
giving it a pixel width that pads the text to an integer number of box
drawing characters.
* (if the enclosed text is editable) Arrange for the above to be
re-done on change.

No, I’m not going to do a prototype.



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

* Re: Enclosing text in a box
  2022-11-16 15:06             ` Yuri Khan
@ 2022-11-16 16:12               ` tomas
  2022-11-16 16:43                 ` Heime
  0 siblings, 1 reply; 32+ messages in thread
From: tomas @ 2022-11-16 16:12 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

On Wed, Nov 16, 2022 at 10:06:22PM +0700, Yuri Khan wrote:
> On Wed, 16 Nov 2022 at 21:55, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> 
> > * OP uses ‘length’ to measure the text, and ‘make-string’ to build a box.

...or, perhaps, just use the :box face attribute. Whose location
in the docs is left as an exercise to the OP.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Enclosing text in a box
  2022-11-16 16:12               ` tomas
@ 2022-11-16 16:43                 ` Heime
  0 siblings, 0 replies; 32+ messages in thread
From: Heime @ 2022-11-16 16:43 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, November 16th, 2022 at 4:12 PM, <tomas@tuxteam.de> wrote:


> On Wed, Nov 16, 2022 at 10:06:22PM +0700, Yuri Khan wrote:
> 
> > On Wed, 16 Nov 2022 at 21:55, Yuri Khan yuri.v.khan@gmail.com wrote:
> > 
> > > * OP uses ‘length’ to measure the text, and ‘make-string’ to build a box.
> 
> 
> ...or, perhaps, just use the :box face attribute. Whose location
> in the docs is left as an exercise to the OP.

There are no examples how to use it exactly.



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

* Re: Enclosing text in a box
  2022-11-16 14:51           ` Heime
  2022-11-16 14:55             ` Emanuel Berg
@ 2022-11-16 16:44             ` Eli Zaretskii
  2022-11-16 16:48               ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-16 16:44 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 16 Nov 2022 14:51:24 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > > The next stumbling point is going to be “make-string does the wrong
> > > thing when passed 17.237 as the count”, without an explanation as to
> > > what the right thing would be. (I don’t know either.)
> > 
> > 
> > Why would sane code call make-string with such an argument?
> 
> The premise seems to be that "string-width" returns it.

Obviously, sane code should round the value up, not use it literally.

> I would like to have the ability to pass unicode characters.

This has nothing to do with Unicode.



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

* Re: Enclosing text in a box
  2022-11-16 16:44             ` Eli Zaretskii
@ 2022-11-16 16:48               ` Heime
  2022-11-16 16:53                 ` Heime
  2022-11-16 19:20                 ` Eli Zaretskii
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-11-16 16:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


------- Original Message -------
On Wednesday, November 16th, 2022 at 4:44 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Wed, 16 Nov 2022 14:51:24 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > The next stumbling point is going to be “make-string does the wrong
> > > > thing when passed 17.237 as the count”, without an explanation as to
> > > > what the right thing would be. (I don’t know either.)
> > > 
> > > Why would sane code call make-string with such an argument?
> > 
> > The premise seems to be that "string-width" returns it.
> 
> 
> Obviously, sane code should round the value up, not use it literally.
> 
> > I would like to have the ability to pass unicode characters.
> 
> 
> This has nothing to do with Unicode.

I do not know whether the unicode characters pose a problem with fractional sizes.




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

* Re: Enclosing text in a box
  2022-11-16 16:48               ` Heime
@ 2022-11-16 16:53                 ` Heime
  2022-11-16 19:20                 ` Eli Zaretskii
  1 sibling, 0 replies; 32+ messages in thread
From: Heime @ 2022-11-16 16:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, November 16th, 2022 at 4:48 PM, Heime <heimeborgia@protonmail.com> wrote:


> ------- Original Message -------
> On Wednesday, November 16th, 2022 at 4:44 PM, Eli Zaretskii eliz@gnu.org wrote:
> 
> 
> 
> > > Date: Wed, 16 Nov 2022 14:51:24 +0000
> > > From: Heime heimeborgia@protonmail.com
> > > Cc: help-gnu-emacs@gnu.org
> > > 
> > > > > The next stumbling point is going to be “make-string does the wrong
> > > > > thing when passed 17.237 as the count”, without an explanation as to
> > > > > what the right thing would be. (I don’t know either.)
> > > > 
> > > > Why would sane code call make-string with such an argument?
> > > 
> > > The premise seems to be that "string-width" returns it.
> > 
> > Obviously, sane code should round the value up, not use it literally.
> > 
> > > I would like to have the ability to pass unicode characters.
> > 
> > This has nothing to do with Unicode.
> 
> 
> I do not know whether the unicode characters pose a problem with fractional sizes.

Would the problem only occur with "non alphanumeric" text?




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

* Re: Enclosing text in a box
  2022-11-16 16:48               ` Heime
  2022-11-16 16:53                 ` Heime
@ 2022-11-16 19:20                 ` Eli Zaretskii
  2022-11-16 19:35                   ` Heime
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-16 19:20 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 16 Nov 2022 16:48:07 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > > I would like to have the ability to pass unicode characters.
> > 
> > 
> > This has nothing to do with Unicode.
> 
> I do not know whether the unicode characters pose a problem with fractional sizes.

Any character can pose such problems.  It depends on the font you are
using.




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

* Re: Enclosing text in a box
  2022-11-16 19:20                 ` Eli Zaretskii
@ 2022-11-16 19:35                   ` Heime
  2022-11-16 19:42                     ` Emanuel Berg
  2022-11-16 20:00                     ` Eli Zaretskii
  0 siblings, 2 replies; 32+ messages in thread
From: Heime @ 2022-11-16 19:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


------- Original Message -------
On Wednesday, November 16th, 2022 at 7:20 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Wed, 16 Nov 2022 16:48:07 +0000
> > From: Heime heimeborgia@protonmail.com
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > I would like to have the ability to pass unicode characters.
> > > 
> > > This has nothing to do with Unicode.
> > 
> > I do not know whether the unicode characters pose a problem with fractional sizes.
> 
> 
> Any character can pose such problems. It depends on the font you are
> using.

So what are people to do?  Basically it means that we cannot rely on "length" and 
"string-width".  Then the function are there for nothing.  Asking users to handle
such conditions would be too hard to do repeatedly.





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

* Re: Enclosing text in a box
  2022-11-16 19:35                   ` Heime
@ 2022-11-16 19:42                     ` Emanuel Berg
  2022-11-16 21:01                       ` Heime
  2022-11-16 20:00                     ` Eli Zaretskii
  1 sibling, 1 reply; 32+ messages in thread
From: Emanuel Berg @ 2022-11-16 19:42 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

> So what are people to do? Basically it means that we cannot
> rely on "length" and "string-width". Then the function are
> there for nothing.

:)

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 19:35                   ` Heime
  2022-11-16 19:42                     ` Emanuel Berg
@ 2022-11-16 20:00                     ` Eli Zaretskii
  2022-11-16 20:55                       ` Emanuel Berg
  2022-11-16 21:04                       ` Emanuel Berg
  1 sibling, 2 replies; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-16 20:00 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 16 Nov 2022 19:35:17 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> > Any character can pose such problems. It depends on the font you are
> > using.
> 
> So what are people to do?

I already advised what to do, in my original message in this thread.

> Basically it means that we cannot rely on "length" and 
> "string-width".

No, it means don't use 'length' (because its purpose is not to measure
the display width).  You _can_ use 'string-width', it will do a good
job in almost all cases.  If you need 110% solution, use
'string-pixel-width'.

> Then the function are there for nothing.

How do you get to such extreme conclusions without even trying what
you were advised to do?

> Asking users to handle such conditions would be too hard to do
> repeatedly.

This is not userland, this is Emacs Lisp programming for display, and
yes, it is quite tricky if you want rock-solid solutions that work
with arbitrary characters and fonts.



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

* Re: Enclosing text in a box
  2022-11-16 20:00                     ` Eli Zaretskii
@ 2022-11-16 20:55                       ` Emanuel Berg
  2022-11-18 14:48                         ` Eli Zaretskii
  2022-11-16 21:04                       ` Emanuel Berg
  1 sibling, 1 reply; 32+ messages in thread
From: Emanuel Berg @ 2022-11-16 20:55 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>> Asking users to handle such conditions would be too hard to
>> do repeatedly.
>
> This is not userland, this is Emacs Lisp programming for
> display, and yes, it is quite tricky

(defun sign (label)
  (interactive "sLabel: ")
  (let*((vertical   "|")
        (horizontal  ?-)
        (corner     "+")
        (mid (format "%s %s %s" vertical label vertical))
        (len (length mid))
        (top (format "%s%s%s" corner (make-string (- len 2) horizontal) corner))
        (sgn (format "%s\n%s\n%s\n" top mid top)) )
    (insert sgn) ))

;; M-x sign This is not a bluff RET
;;
;; +---------------------+
;; | This is not a bluff |
;; +---------------------+

https://dataswamp.org/~incal/emacs-init/string.el

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 14:55             ` Emanuel Berg
@ 2022-11-16 20:56               ` Emanuel Berg
  0 siblings, 0 replies; 32+ messages in thread
From: Emanuel Berg @ 2022-11-16 20:56 UTC (permalink / raw)
  To: help-gnu-emacs

>> The premise seems to be that "string-width" returns it.
>> I would like to have the ability to pass
>> unicode characters.
>
> Didn't Jean do exactly this very recently on
> gmane.emacs.help ?

+-------------------------------------------+
| This message is for display purposes only |
+-------------------------------------------+

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 19:42                     ` Emanuel Berg
@ 2022-11-16 21:01                       ` Heime
  0 siblings, 0 replies; 32+ messages in thread
From: Heime @ 2022-11-16 21:01 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs





------- Original Message -------
On Wednesday, November 16th, 2022 at 7:42 PM, Emanuel Berg <incal@dataswamp.org> wrote:


> Heime wrote:
> 
> > So what are people to do? Basically it means that we cannot
> > rely on "length" and "string-width". Then the function are
> > there for nothing.
> 
> 
> :)
> 

Perhaps 

(ceiling (string-width phallus))



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

* Re: Enclosing text in a box
  2022-11-16 20:00                     ` Eli Zaretskii
  2022-11-16 20:55                       ` Emanuel Berg
@ 2022-11-16 21:04                       ` Emanuel Berg
  1 sibling, 0 replies; 32+ messages in thread
From: Emanuel Berg @ 2022-11-16 21:04 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>> Asking users to handle such conditions would be too hard [...]
>
> [...] this is Emacs Lisp programming

You better believe it - it's like at the very epicentrum
of things!

Only the very, very best can do it, and sometimes seven days
a week.

(defun sign (label &optional no-insert)
  (interactive "sLabel: \nP")
  (let*((vertical   "|")
        (horizontal  ?-)
        (corner     "+")
        (mid (format "%s %s %s" vertical label vertical))
        (len (length mid))
        (top (format "%s%s%s" corner (make-string (- len 2) horizontal) corner))
        (sgn (format "%s\n%s\n%s\n" top mid top)) )
    (if no-insert
        sgn
      (insert sgn) )))

;; +---------------------+
;; | This is not a bluff |
;; +---------------------+

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 12:47 Enclosing text in a box Heime
  2022-11-16 13:07 ` Heime
@ 2022-11-17  6:43 ` Jean Louis
  2022-11-17  6:57   ` Emanuel Berg
  2022-11-18 16:20   ` [External] : " Drew Adams
  1 sibling, 2 replies; 32+ messages in thread
From: Jean Louis @ 2022-11-17  6:43 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

* Heime <heimeborgia@protonmail.com> [2022-11-16 15:49]:
> 
> Would like to enclose some text in a box?  The box has to automatically adjust its size
> according to the size of the text.
> 
>       (insert "╔══════╗\n")
>       (insert (concat "║" text "║\n" ))
>       (insert "╚══════╝" )

I did not read the rest of answers to your question.

Package is here:

Emacs Lisp: rcd-box.el package for table drawings:
https://hyperscope.link/7/3/9/8/1/Emacs-Lisp-rcd-box-el-package-for-table-drawings-73981.html

Basic function:

(rcd-box-table '(("My text"))) ⇒ "
╔═════════╗
║ My text ║
╚═════════╝

"

If you wish to make it simpler:

(defun rcd-box-text (text)
  (rcd-box-table (list (list text))))

(rcd-box-text "Hello") ⇒ "
╔═══════╗
║ Hello ║
╚═══════╝

"

;; Available box drawing types: DOUBLE, HEAVY, LIGHT

That means you can do:


(rcd-box-table '(("My text")) nil "center" "double") ⇒ "
╔═════════╗
║ My text ║
╚═════════╝

"

(rcd-box-table '(("My text")) nil "center" "heavy") ⇒ "
┏━━━━━━━━━┓
┃ My text ┃
┗━━━━━━━━━┛

"

(rcd-box-table '(("My text")) nil "center" "light") ⇒ "
┌─────────┐
│ My text │
└─────────┘

"

and then you can add it to simpler function like:

(defun rcd-box-text (text &optional type)
  (rcd-box-table (list (list text)) nil "center" type))

(rcd-box-text "And now good bye to all" "heavy") ⇒ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ And now good bye to all ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━┛

"


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Enclosing text in a box
  2022-11-17  6:43 ` Jean Louis
@ 2022-11-17  6:57   ` Emanuel Berg
  2022-11-18 19:11     ` Jean Louis
  2022-11-18 16:20   ` [External] : " Drew Adams
  1 sibling, 1 reply; 32+ messages in thread
From: Emanuel Berg @ 2022-11-17  6:57 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
> ┃ And now good bye to all ┃
> ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛

Can you use your program to make a neat table out of
this, perhaps?

It looks neat below but I post-processed it. I mean,
e-manually ...

;;; -*- lexical-binding: t -*-
;;
;; this file
;;   https//dataswamp.org/~incal/emacs-init/war.el

(require 'math)

(defun war ()
  (let*((ukr  603628)
        (pre   42000)
        (smo  119000)
        (ret   74443)
        (most (+ pre smo))
        (now  (- most ret)) )
    (insert (format "Ukraine area %d (km2)\n"                 ukr)
            (format "Occupied pre-2022 %d %s\n"               pre  (percent pre  ukr t))
            (format "Additionally occupied in 2022 %d %s\n"   smo  (percent smo  ukr t))
            (format "Biggest area occupied %d %s\n"           most (percent most ukr t))
            (format "Retaken during counteroffensive %d %s\n" ret  (percent ret most t))
            (format "Occupied area 2022-11-17 %d %s\n"        now  (percent now  ukr t)) )))

;; Ukraine area (km2)               603 628
;; Occupied pre-2022                 42 000   7.0%
;; Additionally occupied in 2022    119 000  19.7%
;; Biggest area occupied            161 000  26.7%
;; Retaken during counteroffensive   74 443  46.2%
;; Occupied area 2022-11-17          86 557  14.3%

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-16 20:55                       ` Emanuel Berg
@ 2022-11-18 14:48                         ` Eli Zaretskii
  2022-11-18 15:10                           ` tomas
  2022-11-18 19:18                           ` Emanuel Berg
  0 siblings, 2 replies; 32+ messages in thread
From: Eli Zaretskii @ 2022-11-18 14:48 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Emanuel Berg <incal@dataswamp.org>
> Date: Wed, 16 Nov 2022 21:55:05 +0100
> 
> Eli Zaretskii wrote:
> 
> >> Asking users to handle such conditions would be too hard to
> >> do repeatedly.
> >
> > This is not userland, this is Emacs Lisp programming for
> > display, and yes, it is quite tricky
> 
> (defun sign (label)
>   (interactive "sLabel: ")
>   (let*((vertical   "|")
>         (horizontal  ?-)
>         (corner     "+")
>         (mid (format "%s %s %s" vertical label vertical))
>         (len (length mid))
>         (top (format "%s%s%s" corner (make-string (- len 2) horizontal) corner))
>         (sgn (format "%s\n%s\n%s\n" top mid top)) )
>     (insert sgn) ))
> 
> ;; M-x sign This is not a bluff RET
> ;;
> ;; +---------------------+
> ;; | This is not a bluff |
> ;; +---------------------+

And now try with "fullwidth" characters, like the below:

  M-x sign RET This is not a bluff RET

This yields:

  +---------------------+
  | This is not a bluff |
  +---------------------+

Hmm...



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

* Re: Enclosing text in a box
  2022-11-18 14:48                         ` Eli Zaretskii
@ 2022-11-18 15:10                           ` tomas
  2022-11-18 19:18                           ` Emanuel Berg
  1 sibling, 0 replies; 32+ messages in thread
From: tomas @ 2022-11-18 15:10 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 286 bytes --]

On Fri, Nov 18, 2022 at 04:48:50PM +0200, Eli Zaretskii wrote:

[...]

> This yields:
> 
>   +---------------------+
>   | This is not a bluff |
>   +---------------------+
> 
> Hmm...

Eeek! It overflows on vim, too!

;-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* RE: [External] : Re: Enclosing text in a box
  2022-11-17  6:43 ` Jean Louis
  2022-11-17  6:57   ` Emanuel Berg
@ 2022-11-18 16:20   ` Drew Adams
  1 sibling, 0 replies; 32+ messages in thread
From: Drew Adams @ 2022-11-18 16:20 UTC (permalink / raw)
  To: Jean Louis, Heime; +Cc: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'

[-- Attachment #1: Type: text/plain, Size: 93 bytes --]

FWIW: related (not quite the same purposes etc.):

https://github.com/davep/boxquote.el


[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 12897 bytes --]

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

* Re: Enclosing text in a box
  2022-11-17  6:57   ` Emanuel Berg
@ 2022-11-18 19:11     ` Jean Louis
  2022-11-21 12:53       ` Emanuel Berg
  0 siblings, 1 reply; 32+ messages in thread
From: Jean Louis @ 2022-11-18 19:11 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-11-18 16:58]:
> Jean Louis wrote:
> 
> > ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
> > ┃ And now good bye to all ┃
> > ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
> 
> Can you use your program to make a neat table out of
> this, perhaps?

I did not put enough parameters to support for example spaces.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Enclosing text in a box
  2022-11-18 14:48                         ` Eli Zaretskii
  2022-11-18 15:10                           ` tomas
@ 2022-11-18 19:18                           ` Emanuel Berg
  1 sibling, 0 replies; 32+ messages in thread
From: Emanuel Berg @ 2022-11-18 19:18 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>> ;; M-x sign This is not a bluff RET
>> ;;
>> ;; +---------------------+
>> ;; | This is not a bluff |
>> ;; +---------------------+
>
> And now try with "fullwidth" characters, like the below:
>
>   M-x sign RET This is not a bluff RET

That's it on the other hand. The bluff.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Enclosing text in a box
  2022-11-18 19:11     ` Jean Louis
@ 2022-11-21 12:53       ` Emanuel Berg
  0 siblings, 0 replies; 32+ messages in thread
From: Emanuel Berg @ 2022-11-21 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
>>> ┃ And now good bye to all ┃
>>> ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
>> 
>> Can you use your program to make a neat table out of
>> this, perhaps?
>
> I did not put enough parameters to support for
> example spaces.

There more you code, the more there is to code ...

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2022-11-21 12:53 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16 12:47 Enclosing text in a box Heime
2022-11-16 13:07 ` Heime
2022-11-16 13:34   ` Alexis Roda
2022-11-16 13:58     ` Eli Zaretskii
2022-11-16 14:11       ` Yuri Khan
2022-11-16 14:20         ` Heime
2022-11-16 14:47         ` Eli Zaretskii
2022-11-16 14:51           ` Heime
2022-11-16 14:55             ` Emanuel Berg
2022-11-16 20:56               ` Emanuel Berg
2022-11-16 16:44             ` Eli Zaretskii
2022-11-16 16:48               ` Heime
2022-11-16 16:53                 ` Heime
2022-11-16 19:20                 ` Eli Zaretskii
2022-11-16 19:35                   ` Heime
2022-11-16 19:42                     ` Emanuel Berg
2022-11-16 21:01                       ` Heime
2022-11-16 20:00                     ` Eli Zaretskii
2022-11-16 20:55                       ` Emanuel Berg
2022-11-18 14:48                         ` Eli Zaretskii
2022-11-18 15:10                           ` tomas
2022-11-18 19:18                           ` Emanuel Berg
2022-11-16 21:04                       ` Emanuel Berg
2022-11-16 14:55           ` Yuri Khan
2022-11-16 15:06             ` Yuri Khan
2022-11-16 16:12               ` tomas
2022-11-16 16:43                 ` Heime
2022-11-17  6:43 ` Jean Louis
2022-11-17  6:57   ` Emanuel Berg
2022-11-18 19:11     ` Jean Louis
2022-11-21 12:53       ` Emanuel Berg
2022-11-18 16:20   ` [External] : " Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.