emacs-devel
[Top][All Lists]
Advanced

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

Re: [External] : Re: discoverability, better defaults and which-key in E


From: Emanuel Berg
Subject: Re: [External] : Re: discoverability, better defaults and which-key in Emacs
Date: Fri, 02 Feb 2024 16:53:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Drew Adams wrote:

>>> I for one would be very interested to know what of my
>>> Elisp I can discard in favor of using stuff in core Emacs.
>>> But I don't have a confident answer how to find out.
>> 
>> Some Emacs commands I suggest for this are:
>>   C-u M-x apropos
>>   M-x apropos-documentation
>>   C-h R elisp RET followed by 'i' (Info-index) and the subject
>
> +1 to all of that.
>
> The most important aid for users - esp. but not only new
> users - is IMHO for them to learn how to better "ask Emacs".

If sorted alphabetically, this is my first Elisp file, abc.el.

After that, the second file, align-from-left.el.

How do I ask Emacs if someone already wrote it and made
it available?

I think part of the problem is before one has programmed it,
it is very difficult to formulate it in an exact way, and one
doesn't always have a clear image what one is doing, even.

I'm not challenging anyone to ask Emacs, rather ... they are
two examples what stuff I have been writing and many, many
times wondered how anyone would ever know, what everyone else
are writing. Someone else must have already written it, right?

Interestingly, it is often easier to find advanced, specialized
stuff than small math and data manipulation functions.
Since they are so general, if one searches, one gets a lot of
hits, a lot of them doing something quite similar but not
exactly the same.

Maybe someone already tried to have Lisp with standard
libraries. Several times?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   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 ?\s (string-to-list abc))
      abc) ))

;; (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
;; (alphabet t) ; (97 98 99 100 101 102 103 104 105 106 107 108 ...)

(defun echo-alphabet (&optional num)
  (interactive "P")
  (or num (setq num (length (alphabet t))))
  (let*((part       (cl-subseq (alphabet t) 0 num))
        (str-list   (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) ))

(defalias 'abc #'echo-alphabet)

;; (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
;; (echo-alphabet   2) ; a b
;; (echo-alphabet  -2) ; a b c d e f g h i j k l m n o p q r s t u v w x
;; (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

(provide 'abc)

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

(require 'cl-lib)

(let ((alf-regexp))
  (defun align-from-left (&optional set-regexp)
    (interactive "p")
    (let ((default-regexp "^\\|[[:punct:]]\\|[[:space:]][[:alnum:]]"))
      (unless (stringp set-regexp)
        (cl-case set-regexp
          ( 4 (setq alf-regexp (read-regexp "regexp: ")))
          (16 (setq alf-regexp default-regexp))
          ( t (unless alf-regexp
                (setq alf-regexp default-regexp) )))))
    (let ((beg (point))
          (re  (or (and (stringp set-regexp) set-regexp)
                    alf-regexp) ))
      (when (re-search-backward re (line-beginning-position) t)
        (while (looking-at "[[:space:]]")
          (forward-char) )
        (insert (make-string (- beg (point)) ?\s)) ))))

(declare-function align-from-left nil)

(provide 'align-from-left)


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




reply via email to

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