all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* complicated code to do trivial (?) thing
@ 2019-06-11 23:50 Emanuel Berg via help-gnu-emacs
  2019-06-12  7:16 ` Anders Dalskov
  0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg via help-gnu-emacs @ 2019-06-11 23:50 UTC (permalink / raw)
  To: help-gnu-emacs

Why isn't this easy to do?

Or is it?

;;; -*- lexical-binding: t -*-

;; This file: http://user.it.uu.se/~embe8573/emacs-init/abc.el
;;            https://dataswamp.org/~incal/emacs-init/abc.el

(require 'cl-lib)

(defun alphabet (&optional as-list)
  (let ((abc "a b c d e f g h i j k l m n o p q r s t u v w x y z"))
    (if as-list
        (cl-remove ?\  (string-to-list abc))
      abc
      )))
;; (alphabet t) ; (97 98 99 100 101 102 103 104 105 106 107 ...)
;; (alphabet)   ; "a b c d e f g h i j k ..."

(defun echo-alphabet (&optional number)
  (interactive "P")
  (let*((num        (or number (length (alphabet t))))
        (part       (cl-subseq (alphabet t) 0 num))
        (str-list   (cl-mapcar (lambda (c) (char-to-string c)) part))
        (str-almost (format "%s" str-list))
        (str        (substring str-almost 1 (1- (length str-almost))))
        )
    (message str) ))
;; (echo-alphabet)     ; "a b c ... x y z"
;; (echo-alphabet  10) ; "a b c d e f g h i j"
;; (echo-alphabet -10) ; "a b c d e f g h i j k l m n o p"
;; (call-interactively #'echo-alphabet)
(defalias 'abc #'echo-alphabet)

(provide 'abc)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: complicated code to do trivial (?) thing
  2019-06-11 23:50 complicated code to do trivial (?) thing Emanuel Berg via help-gnu-emacs
@ 2019-06-12  7:16 ` Anders Dalskov
  2019-06-14 19:41   ` Emanuel Berg via help-gnu-emacs
  2019-07-10  0:08   ` Emanuel Berg via help-gnu-emacs
  0 siblings, 2 replies; 9+ messages in thread
From: Anders Dalskov @ 2019-06-12  7:16 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

It can be simplified somewhat, I think. My take is below. Instead of
`cl-remove' you can use `split-string', and instead of `mapcar' +
`format' + `substring' you can use `mapconcat'.


(defun alphabet (&optional as-list)
  (let ((abc "a b c d e f g h i j k l m n o p q r s t u v w x y z"))
    (if as-list
	(split-string abc)
      abc)))

(defun echo-alphabet (&optional number)
  (interactive "P")
  (let* ((abc-as-list (alphabet t))
	 (number (or number (length abc-as-list))))
    (mapconcat 'identity (subseq abc-as-list 0 number) " ")))


Also, if you don't need the alphabet function (or you only want to use
the english alphabet), then you should probably just assign
`abc-as-list' directly and remove the `alphabet' function.

Emanuel Berg via help-gnu-emacs writes:

> Why isn't this easy to do?
>
> Or is it?
>
> ;;; -*- lexical-binding: t -*-
>
> ;; This file: http://user.it.uu.se/~embe8573/emacs-init/abc.el
> ;;            https://dataswamp.org/~incal/emacs-init/abc.el
>
> (require 'cl-lib)
>
> (defun alphabet (&optional as-list)
>   (let ((abc "a b c d e f g h i j k l m n o p q r s t u v w x y z"))
>     (if as-list
>         (cl-remove ?\  (string-to-list abc))
>       abc
>       )))
> ;; (alphabet t) ; (97 98 99 100 101 102 103 104 105 106 107 ...)
> ;; (alphabet)   ; "a b c d e f g h i j k ..."
>
> (defun echo-alphabet (&optional number)
>   (interactive "P")
>   (let*((num        (or number (length (alphabet t))))
>         (part       (cl-subseq (alphabet t) 0 num))
>         (str-list   (cl-mapcar (lambda (c) (char-to-string c)) part))
>         (str-almost (format "%s" str-list))
>         (str        (substring str-almost 1 (1- (length str-almost))))
>         )
>     (message str) ))
> ;; (echo-alphabet)     ; "a b c ... x y z"
> ;; (echo-alphabet  10) ; "a b c d e f g h i j"
> ;; (echo-alphabet -10) ; "a b c d e f g h i j k l m n o p"
> ;; (call-interactively #'echo-alphabet)
> (defalias 'abc #'echo-alphabet)
>
> (provide 'abc)


--
- Anders



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

* Re: complicated code to do trivial (?) thing
  2019-06-12  7:16 ` Anders Dalskov
@ 2019-06-14 19:41   ` Emanuel Berg via help-gnu-emacs
  2019-07-10  0:08   ` Emanuel Berg via help-gnu-emacs
  1 sibling, 0 replies; 9+ messages in thread
From: Emanuel Berg via help-gnu-emacs @ 2019-06-14 19:41 UTC (permalink / raw)
  To: help-gnu-emacs

Anders Dalskov wrote:

> It can be simplified somewhat, I think.
> My take is below. Instead of `cl-remove' you
> can use `split-string', and instead of
> `mapcar' + `format' + `substring' you can use
> `mapconcat'.
>
> (defun alphabet (&optional as-list)
>   (let ((abc "a b c d e f g h i j k l m n o p q r s t u v w x y z"))
>     (if as-list
> 	(split-string abc)
>       abc)))
>
> (defun echo-alphabet (&optional number)
>   (interactive "P")
>   (let* ((abc-as-list (alphabet t))
> 	 (number (or number (length abc-as-list))))
>     (mapconcat 'identity (subseq abc-as-list 0 number) " ")))

That looks much better, yes. Thank you, will
try it out, examine the code, and if it works
as well as mine ;) I will replace it, and put
your initials next it it.

Mange tak!

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: complicated code to do trivial (?) thing
  2019-06-12  7:16 ` Anders Dalskov
  2019-06-14 19:41   ` Emanuel Berg via help-gnu-emacs
@ 2019-07-10  0:08   ` Emanuel Berg via help-gnu-emacs
  2019-07-10  8:11     ` Anders Dalskov
  1 sibling, 1 reply; 9+ messages in thread
From: Emanuel Berg via help-gnu-emacs @ 2019-07-10  0:08 UTC (permalink / raw)
  To: help-gnu-emacs

I wierd problem with messages has appeared
in the system.

It is described - or shown - in the source
file [1], ~downmost, or lines 28-34.

But in short, sometimes the echoed message is
the intended

    a b c d e f g h i j k l m n o p q r s t u v w x y z

or

    a b c d e f g h i j k l m n o p

but sometimes both examples (see the file)
produces abbreviated messages, actually the
same one:

    a b c d e f g h i j k l ...

Are long messages matched against messages
already showed or showed recently and
abbreviated as they are considered redundant as
"have already been showed"?

What do you know? What do you think?
Excepts I should learn the English
alphabet already?


[1] https://dataswamp.org/~incal/emacs-init/abc.el

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: complicated code to do trivial (?) thing
  2019-07-10  0:08   ` Emanuel Berg via help-gnu-emacs
@ 2019-07-10  8:11     ` Anders Dalskov
  2019-07-10  8:59       ` Emanuel Berg via help-gnu-emacs
  0 siblings, 1 reply; 9+ messages in thread
From: Anders Dalskov @ 2019-07-10  8:11 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Emacs sometimes inserts an ellipsis if the result is longer than some
threshold (what that threshold is, I don't know).

Though this only happens with s-expressions, not strings, afaict. 

Emanuel Berg via help-gnu-emacs writes:

> I wierd problem with messages has appeared
> in the system.
>
> It is described - or shown - in the source
> file [1], ~downmost, or lines 28-34.
>
> But in short, sometimes the echoed message is
> the intended
>
>     a b c d e f g h i j k l m n o p q r s t u v w x y z
>
> or
>
>     a b c d e f g h i j k l m n o p
>
> but sometimes both examples (see the file)
> produces abbreviated messages, actually the
> same one:
>
>     a b c d e f g h i j k l ...
>
> Are long messages matched against messages
> already showed or showed recently and
> abbreviated as they are considered redundant as
> "have already been showed"?
>
> What do you know? What do you think?
> Excepts I should learn the English
> alphabet already?
>
>
> [1] https://dataswamp.org/~incal/emacs-init/abc.el


-- 
- Anders



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

* Re: complicated code to do trivial (?) thing
  2019-07-10  8:11     ` Anders Dalskov
@ 2019-07-10  8:59       ` Emanuel Berg via help-gnu-emacs
  2019-07-10  9:34         ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg via help-gnu-emacs @ 2019-07-10  8:59 UTC (permalink / raw)
  To: help-gnu-emacs

Anders Dalskov wrote:

> Emacs sometimes inserts an ellipsis if the
> result is longer than some threshold (what
> that threshold is, I don't know).
>
> Though this only happens with s-expressions,
> not strings, afaict.

Okay, but the strangest thing is sometimes
I get the entire string, sometimes the
"insertion of ellipsis", for the same command
and result! Same result, I assume! Otherwise it
is even more strange...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: complicated code to do trivial (?) thing
  2019-07-10  8:59       ` Emanuel Berg via help-gnu-emacs
@ 2019-07-10  9:34         ` tomas
  0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2019-07-10  9:34 UTC (permalink / raw)
  To: help-gnu-emacs

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

On Wed, Jul 10, 2019 at 10:59:38AM +0200, Emanuel Berg via help-gnu-emacs wrote:
> Anders Dalskov wrote:
> 
> > Emacs sometimes inserts an ellipsis if the
> > result is longer than some threshold (what
> > that threshold is, I don't know).
> >
> > Though this only happens with s-expressions,
> > not strings, afaict.
> 
> Okay, but the strangest thing is sometimes
> I get the entire string, sometimes the
> "insertion of ellipsis", for the same command
> and result! Same result, I assume! Otherwise it
> is even more strange...

You're most probably seeing this abbreviation in the message
line (which ends up in *Messages* or something).

There are two levels here:

The "print" function, which is the generic S-expression printer,
obeys two variables: "print-length" and "print-level", which can
limit how wide and deep to print S-expressions. By default they
are both nil, which means "print everything.

For the message area, "eval-expression" calls on "print" to
present the results, but "eval-expression-print-length" and
"eval-expression-print-depth" take over, and by default, both
are set to finite values.

Cheers
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: complicated code to do trivial (?) thing
@ 2019-07-10 17:34 Joe Trivers via help-gnu-emacs
  2019-07-10 18:10 ` Joe Trivers via help-gnu-emacs
  0 siblings, 1 reply; 9+ messages in thread
From: Joe Trivers via help-gnu-emacs @ 2019-07-10 17:34 UTC (permalink / raw)
  To: anderspkd, moasenwood; +Cc: help-gnu-emacs

> From: help-gnu-emacs On Behalf Of Anders Dalskov
> Sent: 10 July, 2019 4:12 AM

> Emacs sometimes inserts an ellipsis if the result is longer than some
> threshold (what that threshold is, I don't know).

> Though this only happens with s-expressions, not strings, afaict.

Are you referring to the last sentence of:

Lisp Interaction mode defined in 'elisp-mode.el':
Major mode for typing and evaluating Lisp forms.
Like Lisp mode except that C-j evals the Lisp expression
before point, and prints its value into the buffer, advancing point.
Note that printing is controlled by 'eval-expression-print-length'
and 'eval-expression-print-level'.

(from C-h m in the *scratch* buffer)?

>> but sometimes both examples (see the file)
>> produces abbreviated messages, actually the
>> same one:
>>
>>     a b c d e f g h i j k l ...
>>
>> [1] https://dataswamp.org/~incal/emacs-init/abc.el

I get "ERR_CONNECTION_RESET" when I click on that file URL.

The content of this message is APPLIED MATERIALS CONFIDENTIAL. If you are not the intended recipient, please notify me, delete this email and do not use or distribute this email.



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

* RE: complicated code to do trivial (?) thing
  2019-07-10 17:34 Joe Trivers via help-gnu-emacs
@ 2019-07-10 18:10 ` Joe Trivers via help-gnu-emacs
  0 siblings, 0 replies; 9+ messages in thread
From: Joe Trivers via help-gnu-emacs @ 2019-07-10 18:10 UTC (permalink / raw)
  To: anderspkd, moasenwood; +Cc: help-gnu-emacs

From: help-gnu-emacs  On Behalf Of Joe Trivers via help-gnu-emacs
Sent: 10 July, 2019 1:34 PM

>>> but sometimes both examples (see the file)
>>> produces abbreviated messages, actually the
>>> same one:
>>>
>>>     a b c d e f g h i j k l ...
>>>
>>> [1] https://dataswamp.org/~incal/emacs-init/abc.el
>
>I get "ERR_CONNECTION_RESET" when I click on that file URL.

Sorry, that was my employer's network nanny. From my home ISP it worked just fine.

(echo-alphabet)
"a b c d e f g h i j k l m n o p q r s t u v w x y z"

(let ((print-length 8))
  (echo-alphabet))
"a b c d e f g h ..."

(let ((print-length 12))
  (echo-alphabet))
"a b c d e f g h i j k l ..."

(let ((eval-expression-print-length 12))
  (echo-alphabet))
"a b c d e f g h i j k l m n o p q r s t u v w x y z"

I haven't experienced any indeterminacy, though.
/Joe
The content of this message is APPLIED MATERIALS CONFIDENTIAL. If you are not the intended recipient, please notify me, delete this email and do not use or distribute this email.



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

end of thread, other threads:[~2019-07-10 18:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-11 23:50 complicated code to do trivial (?) thing Emanuel Berg via help-gnu-emacs
2019-06-12  7:16 ` Anders Dalskov
2019-06-14 19:41   ` Emanuel Berg via help-gnu-emacs
2019-07-10  0:08   ` Emanuel Berg via help-gnu-emacs
2019-07-10  8:11     ` Anders Dalskov
2019-07-10  8:59       ` Emanuel Berg via help-gnu-emacs
2019-07-10  9:34         ` tomas
  -- strict thread matches above, loose matches on Subject: below --
2019-07-10 17:34 Joe Trivers via help-gnu-emacs
2019-07-10 18:10 ` Joe Trivers via help-gnu-emacs

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.