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

Bug#692060: remove shell-command.el from emacs-goodies-el



David Bremner <david@tethera.net> writes:

>> It looks like much of shell-command is already available in emacs
>> itself, so if there're any pieces that should be preserved, where should
>> they go?
>
> Into a separate package if they are substantial enough to warrant it.
> If not, that's a bit trickier.  If it's just a few lines of
> customization I guess the options include upstream bug-reports (to emacs
> in general or to the appropriate package) and a page in emacswiki.org.
> Maybe someone-who-is-not-me would be interested in curating a collection
> of such bits, but it's not clear to me why that needs to happen
> primarily as a Debian package. I guess one possibility is that someone
> steps up to maintain a much reduced emacs-goodies-el that would contain
> only those bits left over.

OK, so shell-command.el provides two things:

1. tab completion
2. a fancier prompt

The tab completion is already provided by default, so we don't need to
worry about it. The fancier prompt maybe would be good to keep, but it's
the case where it's just a bit of config, not really warranting a whole
package. In my init.el I've had this for years:

  (defadvice read-shell-command (before
                                 shell-command-add-directory-to-prompt
                                 (prompt &rest r)
                                 activate)
    "adds the current path to the shell-command minibuffer prompt"
    (let ((footer
           (shell-command-make-prompt-string " [%w]%$ " default-directory)))
      (and (string-match ": $" prompt)
           (setq prompt (replace-match footer t t prompt)))))


So all I'm using from shell-command is this:


  (put 'shell-command/static-if 'lisp-indent-function 2)
  (defmacro shell-command/static-if (cond then &rest else)
    (if (eval cond) then (cons 'progn else)))

  (defun shell-command-make-prompt-string (format-string current-directory) "\
  Function to generate prompt string

  Use FORMAT-STRING to generate prompt string at the directory
  CURRENT-DIRECTORY.  The following `%' escapes are available for use in
  FORMAT-STRING:

  %d     the date in \"Weekday Month Date\" format \(e.g., \"Tue May 26\"\)
  %h     the hostname up to the first `.'
  %H     the hostname
  %t     the current time in 24-hour HH:MM:SS format
  %T     the current time in 12-hour HH:MM:SS format
  %@     the current time in 12-hour am/pm format
  %u     the username of the current user
  %w     the current working directory
  %W     the basename of the current working directory
  %$     if the effective UID is 0, a #, otherwise a $
  %%     Insert a literal `%'.
  "
    (let ((case-fold-search nil)
          start buf
          (list (list format-string))
          (alist (let ((system-name (system-name))
                       host-name
                       fqdn-name
                       (time (current-time))
                       (dir (directory-file-name
                             (abbreviate-file-name current-directory))))
                   (shell-command/static-if (featurep 'xemacs)
                       (cond
                        ((string= dir (user-home-directory))
                         (setq dir "~"))
                        ((string-match (concat "^"
                                               (regexp-quote
                                                (file-name-as-directory
                                                 (user-home-directory))))
                                       dir)
                         (setq dir
                               (concat "~/" (substring dir (match-end 0)))))))
                   (if (string-match "^\\([^.]+\\)\\.[^.]" system-name)
                       (setq fqdn-name system-name
                             host-name (match-string 1 system-name))
                     (setq host-name system-name
                           fqdn-name
                           (cond
                            ((and (boundp 'mail-host-address)
                                  (stringp mail-host-address)
                                  (string-match "\\." mail-host-address))
                             mail-host-address)
                            ((and user-mail-address
                                  (string-match "\\." user-mail-address)
                                  (string-match "@\\(.*\\)\\'"
                                                user-mail-address))
                             (match-string 1 user-mail-address))
                            (t system-name))))
                   `(("%%" . "%")
                     ("%d" . ,(format-time-string "%a %b %e" time))
                     ("%h" . ,host-name)
                     ("%H" . ,fqdn-name)
                     ("%t" . ,(format-time-string "%H:%M:%S" time))
                     ("%T" . ,(format-time-string "%I:%M:%S" time))
                     ("%@" . ,(format-time-string "%I:%M%p" time))
                     ("%u" . ,(user-login-name))
                     ("%w" . ,dir)
                     ("%W" . ,(file-name-nondirectory
                               (directory-file-name current-directory)))
                     ("%\\$" . ,(if (= (user-uid) 0) "#" "$"))))))
      (while alist
        (setq buf nil)
        (while list
          (setq start 0)
          (while (string-match (car (car alist)) (car list) start)
            (setq buf (cons (cdr (car alist))
                            (cons (substring (car list) start
                                             (match-beginning 0))
                                  buf))
                  start (match-end 0)))
          (setq buf (cons (substring (car list) start) buf)
                list (cdr list)))
        (setq list (nreverse buf)
              alist (cdr alist)))
      (apply 'concat list)))

For MY use case I don't even need all that because I can simply replace

  (shell-command-make-prompt-string " [%w]%$ " default-directory)

with

  (format " [%s]$ " (directory-file-name (abbreviate-file-name default-directory)))

I don't think anything here is worth maintaining. If this goes away,
should we think about how to not blow up peoples' existing usages?


Reply to: