emacs-devel
[Top][All Lists]
Advanced

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

Re: scratch/command 064f146 1/2: Change command to interactive ... modes


From: Juri Linkov
Subject: Re: scratch/command 064f146 1/2: Change command to interactive ... modes
Date: Wed, 17 Feb 2021 10:58:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> To my mind, if two forms of writing the same thing are equally clear and
> easy to understand, the less verbose one is often the better choice.
> But I would claim that the more verbose form in this case is less clear
> and harder to understand.

The question is how this form is less clear and harder to understand:

(defun Info-follow-reference (footnotename &optional fork)
  (declare (completion Info-mode))
  ================================
  (interactive
   (let ((completion-ignore-case t)
         (case-fold-search t)
         completions default alt-default (start-point (point)) str i bol eol)
     (save-excursion
       ;; Store end and beginning of line.
       (setq eol (line-end-position)
             bol (line-beginning-position))
       (goto-char (point-min))
       (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
         (setq str (match-string-no-properties 1))
         ;; See if this one should be the default.
         (and (null default)
              (<= (match-beginning 0) start-point)
              (<= start-point (point))
              (setq default t))
         ;; See if this one should be the alternate default.
         (and (null alt-default)
              (and (<= bol (match-beginning 0))
                   (<= (point) eol))
              (setq alt-default t))
         (setq i 0)
         (while (setq i (string-match "[ \n\t]+" str i))
           (setq str (concat (substring str 0 i) " "
                             (substring str (match-end 0))))
           (setq i (1+ i)))
         ;; Record as a completion and perhaps as default.
         (if (eq default t) (setq default str))
         (if (eq alt-default t) (setq alt-default str))
         ;; Don't add this string if it's a duplicate.
         (or (assoc-string str completions t)
             (push str completions))))
     ;; If no good default was found, try an alternate.
     (or default
         (setq default alt-default))
     ;; If only one cross-reference found, then make it default.
     (if (eq (length completions) 1)
         (setq default (car completions)))
     (if completions
         (let ((input (completing-read (if default
                                           (concat
                                            "Follow reference named (default "
                                            default "): ")
                                         "Follow reference named: ")
                                       completions nil t)))
           (list (if (equal input "")
                     default input)
                 current-prefix-arg))
       (user-error "No cross-references in this node"))))

than what we have now in master (see the difference at the end):

(defun Info-follow-reference (footnotename &optional fork)
  (interactive
   (let ((completion-ignore-case t)
         (case-fold-search t)
         completions default alt-default (start-point (point)) str i bol eol)
     (save-excursion
       ;; Store end and beginning of line.
       (setq eol (line-end-position)
             bol (line-beginning-position))
       (goto-char (point-min))
       (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
         (setq str (match-string-no-properties 1))
         ;; See if this one should be the default.
         (and (null default)
              (<= (match-beginning 0) start-point)
              (<= start-point (point))
              (setq default t))
         ;; See if this one should be the alternate default.
         (and (null alt-default)
              (and (<= bol (match-beginning 0))
                   (<= (point) eol))
              (setq alt-default t))
         (setq i 0)
         (while (setq i (string-match "[ \n\t]+" str i))
           (setq str (concat (substring str 0 i) " "
                             (substring str (match-end 0))))
           (setq i (1+ i)))
         ;; Record as a completion and perhaps as default.
         (if (eq default t) (setq default str))
         (if (eq alt-default t) (setq alt-default str))
         ;; Don't add this string if it's a duplicate.
         (or (assoc-string str completions t)
             (push str completions))))
     ;; If no good default was found, try an alternate.
     (or default
         (setq default alt-default))
     ;; If only one cross-reference found, then make it default.
     (if (eq (length completions) 1)
         (setq default (car completions)))
     (if completions
         (let ((input (completing-read (if default
                                           (concat
                                            "Follow reference named (default "
                                            default "): ")
                                         "Follow reference named: ")
                                       completions nil t)))
           (list (if (equal input "")
                     default input)
                 current-prefix-arg))
       (user-error "No cross-references in this node")))
   Info-mode)
   =========



reply via email to

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