Subject: Initialization of `dired-mode-map' in by the `dired-x' feature is not safe

From: Alexander Shukaev <[email-masked]>
Date: Tue, 13 Dec 2016 01:52:31 +0100

Hi,

consider the two

;;; KEY BINDINGS.

(define-key dired-mode-map "\C-x\M-o" 'dired-omit-mode)
(define-key dired-mode-map "*O" 'dired-mark-omitted)
(define-key dired-mode-map "\M-(" 'dired-mark-sexp)
(define-key dired-mode-map "*(" 'dired-mark-sexp)
(define-key dired-mode-map "*." 'dired-mark-extension)
(define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
(define-key dired-mode-map "\M-G" 'dired-goto-subdir)
(define-key dired-mode-map "F" 'dired-do-find-marked-files)
(define-key dired-mode-map "Y"  'dired-do-relsymlink)
(define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp)
(define-key dired-mode-map "V" 'dired-do-run-mail)

;;; MENU BINDINGS

(require 'easymenu)

(let ((menu (lookup-key dired-mode-map [menu-bar])))
   (easy-menu-add-item menu '("Operate")
                       ["Find Files" dired-do-find-marked-files
                        :help "Find current or marked files"]
                       "Shell Command...")
   (easy-menu-add-item menu '("Operate")
                       ["Relative Symlink to..." dired-do-relsymlink
                        :visible (fboundp 'make-symbolic-link)
                        :help "Make relative symbolic links for current or \
marked files"]
                       "Hardlink to...")
   (easy-menu-add-item menu '("Mark")
                       ["Flag Extension..." dired-flag-extension
                        :help "Flag files with a certain extension for 
deletion"]
                       "Mark Executables")
   (easy-menu-add-item menu '("Mark")
                       ["Mark Extension..." dired-mark-extension
                        :help "Mark files with a certain extension"]
                       "Unmark All")
   (easy-menu-add-item menu '("Mark")
                       ["Mark Omitted" dired-mark-omitted
                        :help "Mark files matching `dired-omit-files' \
and `dired-omit-extensions'"]
                       "Unmark All")
   (easy-menu-add-item menu '("Regexp")
                       ["Relative Symlink..." dired-do-relsymlink-regexp
                        :visible (fboundp 'make-symbolic-link)
                        :help "Make relative symbolic links for files \
matching regexp"]
                       "Hardlink...")
   (easy-menu-add-item menu '("Immediate")
                       ["Omit Mode" dired-omit-mode
                        :style toggle :selected dired-omit-mode
                        :help "Enable or disable omitting 
\"uninteresting\" \
files"]
                       "Refresh"))

sections.  Both can easily fail.  For instance,

(define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp)

assumes that the "%" prefix command has been defined in `dired-mode-map' 
which is not at all true for any customization.  The 
`easy-menu-add-item' calls suffers from similar issue.  It should be 
possible to conditionally disable these code sections or even remove 
them altogether as they are maldesigned.

Looking forward to fix.

P.S. Just a side question: why `dired-x' is not yet merged into `dired'? 
  IMO, makes no sense to maintain separate extension packages of the 
main package when they are already built-in anyway.

Regards,
Alexander