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

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

Re: terminal command with output in current buffer


From: Emanuel Berg
Subject: Re: terminal command with output in current buffer
Date: Tue, 20 Jul 2021 01:12:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>> (let*((read-result (read-from-minibuffer "Prompt: "))
>
> Please don't use `read-from-minibuffer` unless you're
> defining a `read-<foo>` function. Use `read-string` instead.

OK, thanks, 5 places to fix...

I wonder what the last function, "replace-regexp-1" is
supposed to do, what the -1 means, and what sets it apart
from what should be there already, is what I'm thinking ... or
am I wrong?

;; in https://dataswamp.org/~incal/emacs-init/edit.el ...

(defun insert-string-centered (str &optional width)
  (interactive
   (list (read-string "string: ")
         (read-number "width: " (window-text-width) ) ))
  (let*((span    (if (and width (< 0 width)) width (window-text-width)))
        (str-len (length str))
        (pad     (- (/ (- span str-len) 2)
                    (if (zerop (mod str-len 2)) 1 0) ))
        (pad-str (make-string pad ?\s)) )
    (insert pad-str str) ))
(defalias 'isc #'insert-string-centered)

;; https://dataswamp.org/~incal/emacs-init/time-cmp.el

(defun dope (from boxes pills dose)
  (interactive
   (list
    (read-string "from: " (format-time-string "%F"))
    (read-number "boxes: ")
    (read-number "pills/box: " 50)
    (read-number "pills/day: "  6) ))
  (let*((days (/ (* boxes pills) dose))
        (done (time-add (date-to-time (format "%sT00:00+01:00" from))
                        (days-to-time (1- days)) ))
        (str  (format-time-string "%F" done))
        (more (format-time-string "%F" (time-add done (days-to-time -10)))) )
    (insert (format "%s  [%s]  %s" from more str) )))

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

(defun sort-line-words (beg end &optional set-delim)
  (interactive "r\nP")
  (let*((str       (region-to-string))
        (delim-str (when set-delim (read-string "delimiter: ")))
        (str-list  (split-string str delim-str))
        (sorted    (erc-sort-strings str-list)) )
    (kill-region beg end)
    (if set-delim
        (progn
          (dolist (s (nreverse (cdr (nreverse sorted))))
            (insert (format "%s%s" s delim-str)))
          (insert (format "%s" (car (last sorted)))))
      (insert-string-list sorted) )))

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

(defun replace-regexp-1 (regexp to-string &optional beg end)
  (interactive
   `(,(read-string "regexp: ")
     ,(read-string "to string: ")
     ,@(if (use-region-p)
           (list (region-beginning) (region-end))
         (list (point-min) (point-max))) ))
  (let ((beg-set (or beg (point-min)))
        (end-set (or end (point-max))) )
    (save-excursion
      (goto-char end-set)
      (while (re-search-backward regexp beg-set t)
        (replace-match to-string) ))))
(defalias 'rr #'replace-regexp-1)

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




reply via email to

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