help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

complicated code to do trivial (?) thing


From: Emanuel Berg
Subject: complicated code to do trivial (?) thing
Date: Wed, 12 Jun 2019 01:50:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]