emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/ergoemacs-mode ead494f: Various tweaks a cleanups to si


From: Stefan Monnier
Subject: [elpa] externals/ergoemacs-mode ead494f: Various tweaks a cleanups to silence compiler warnings
Date: Fri, 20 Feb 2015 20:31:13 +0000

branch: externals/ergoemacs-mode
commit ead494f238f20d87b6f209e0c60e7b72847c771d
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    Various tweaks a cleanups to silence compiler warnings
    
    * ergoemacs-advices.el (define-key): Use `eq' and don't presume that
    ergoemacs-keymap is bound.
    
    * ergoemacs-macros.el: Require CL before using its macros.
    (ergoemacs-theme-component--parse-keys-and-body): Use defun rather
    than fset.  Remove condition-case around code that can't signal errors.
    Simplify.
    
    * ergoemacs-shortcuts.el (ergoemacs-read-key): Prefer consp over
    type-of.
    (ergoemacs-shortcut-function-binding): Use `or' and `nreverse'.
    (ergoemacs-shortcut-remap-list):
    * ergoemacs-mode.el (ergoemacs-is-movement-command-p): Prefer stringp
    over type-of.
    
    * ergoemacs-theme-engine.el (ergoemacs-theme-obj-install)
    (ergoemacs-theme-component--ignore-globally-defined-key): Circumvent
    the problematic use of `adjoin'.
    (ergoemacs-require, ergoemacs-theme-option-on): Prefer consp over
    type-of.
    
    * ergoemacs-translate.el (ergoemacs-pretty-key): Use \` and \' to match
    beginning/end of string.
    (ergoemacs-translation): Avoid add-to-list.  Don't call `macroexpand'
    since `eval' will do that for us anyway.
    (ergoemacs-setup-translation): Avoid add-to-list.
    
    * ergoemacs-unbind.el (ergoemacs-undefined): Use `boundp' over
    `featurep' to silence a compiler warning.  Remove unneeded
    `ignore-errors'.
    (ergoemacs-global-fix-default-bindings): Rename from
    ergoemacs-global-fix-defualt-bindings, update all callers.
    (ergoemacs-global-changed-p): Prefer stringp over type-of.
    Remove unneeded `ignore-errors'.
    (ergoemacs-warn-globally-changed-keys): Prefer stringp over type-of.
---
 .gitignore                |    3 +
 ergoemacs-advices.el      |   12 +++--
 ergoemacs-extras.el       |    9 ++--
 ergoemacs-macros.el       |   86 +++++++++++++++++----------------
 ergoemacs-menus.el        |    2 +-
 ergoemacs-mode.el         |    2 +-
 ergoemacs-shortcuts.el    |   31 +++++++-----
 ergoemacs-theme-engine.el |   37 +++++++-------
 ergoemacs-themes.el       |    2 +-
 ergoemacs-translate.el    |   89 +++++++++++++++++-----------------
 ergoemacs-unbind.el       |  116 ++++++++++++++++++++++----------------------
 11 files changed, 200 insertions(+), 189 deletions(-)

diff --git a/.gitignore b/.gitignore
index edb2219..fdd4531 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,8 @@
 *~
 out/*
+ChangeLog
+*-autoloads.el
+*-pkg.el
 *.elc
 \#*\#
 .\#*
diff --git a/ergoemacs-advices.el b/ergoemacs-advices.el
index 5aa11da..8646d18 100644
--- a/ergoemacs-advices.el
+++ b/ergoemacs-advices.el
@@ -28,7 +28,7 @@
 
 ;;; Code:
 
-(eval-when-compile 
+(eval-when-compile
   (require 'cl)
   (require 'ergoemacs-macros))
 
@@ -71,7 +71,7 @@ If `pre-command-hook' is used and `ergoemacs-mode' is remove 
from `ergoemacs-pre
 (defadvice define-key (around ergoemacs-define-key-advice (keymap key def) 
activate)
   "This does the right thing when modifying `ergoemacs-keymap'.
 Also adds keymap-flag for user-defined keys run with `run-mode-hooks'."
-  (let ((is-global-p (equal keymap (current-global-map)))
+  (let ((is-global-p (eq keymap (current-global-map)))
         (is-local-p (equal keymap (current-local-map)))
         ergoemacs-local-map)
     (when (and is-local-p (not ergoemacs-local-emulation-mode-map-alist))
@@ -85,8 +85,9 @@ Also adds keymap-flag for user-defined keys run with 
`run-mode-hooks'."
     ;;   (setq ergoemacs-local-emulation-mode-map-alist
     ;;         (list (cons 'ergoemacs-mode (make-sparse-keymap)))))
     (if (and ergoemacs-run-mode-hooks
-             (not (equal keymap ergoemacs-global-map))
-             (not (equal keymap ergoemacs-keymap)))
+             (not is-global-p)
+             (not (and (boundp 'ergoemacs-keymap)
+                       (eq keymap ergoemacs-keymap))))
         (let ((ergoemacs-run-mode-hooks nil)
               (new-key (read-kbd-macro
                         (format "<ergoemacs-user> %s"
@@ -117,7 +118,8 @@ Also adds keymap-flag for user-defined keys run with 
`run-mode-hooks'."
                        (string= "ESC" kd)))
         ;; Let `ergoemacs-mode' know these keys have changed.
         (pushnew kd ergoemacs-global-changed-cache :test 'equal)
-        (setq ergoemacs-global-not-changed-cache (delete kd 
ergoemacs-global-not-changed-cache))
+        (setq ergoemacs-global-not-changed-cache
+              (delete kd ergoemacs-global-not-changed-cache))
         ;; Remove the key from `ergoemacs-mode' bindings
         (ergoemacs-theme-component--ignore-globally-defined-key key t)))))
 
diff --git a/ergoemacs-extras.el b/ergoemacs-extras.el
index f7de815..922eeda 100644
--- a/ergoemacs-extras.el
+++ b/ergoemacs-extras.el
@@ -1124,7 +1124,7 @@ Files are generated in the dir 〔ergoemacs-extras〕 at 
`user-emacs-directory'.
     ;; made by ergoemacs.
     ;; (mapc
     ;;  (lambda(minor-list)
-    ;;    (when (eq (type-of (nth 1 minor-list)) 'cons)
+    ;;    (when (consp (nth 1 minor-list))
     ;;      (mapc
     ;;       (lambda(translation-list)
     ;;         (when (eq (nth 1 x) (nth 1 translation-list))
@@ -1136,9 +1136,10 @@ Files are generated in the dir 〔ergoemacs-extras〕 at 
`user-emacs-directory'.
     ;;  (symbol-value (ergoemacs-get-minor-mode-layout)))
     (list (if var-layout
               (ergoemacs-kbd (nth 0 x) t (nth 3 x))
-            (nth 0 x)) (nth 2 x)  num cmds
-            (format "%6.2f%%" (/ (* 1e2 num) cmd-n))
-            (format "%6.2f%%" (/ (* 1e2 num) total-n)))))
+            (nth 0 x))
+          (nth 2 x)  num cmds
+          (format "%6.2f%%" (/ (* 1e2 num) cmd-n))
+          (format "%6.2f%%" (/ (* 1e2 num) total-n)))))
 
 (defvar keyfreq-table)
 (declare-function keyfreq-table-load "keyfreq.el")
diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el
index aa23909..ddde13a 100644
--- a/ergoemacs-macros.el
+++ b/ergoemacs-macros.el
@@ -1,6 +1,6 @@
 ;;; ergoemacs-macros.el --- Macros for ergoemacs-mode -*- lexical-binding: t 
-*-
 
-;; Copyright © 2013, 2014  Free Software Foundation, Inc.
+;; Copyright © 2013, 2014, 2015  Free Software Foundation, Inc.
 
 ;; Maintainer: Matthew L. Fidler
 ;; Keywords: convenience
@@ -29,6 +29,7 @@
 ;;; Code:
 
 ;; These should only be called when byte compiled
+(eval-when-compile (require 'cl))       ;FIXME: Use cl-lib instead!
 
 ;;;###autoload
 (defmacro ergoemacs-with-ergoemacs (&rest body)
@@ -228,7 +229,9 @@ Uses `ergoemacs-theme-component--parse-keys-and-body' and
                 (lambda() ,(plist-get (nth 0 kb) ':description)
                   (ergoemacs-theme-component--create-component
                    ',(nth 0 kb)
-                   '(lambda () ,@(nth 1 kb)))) ergoemacs-theme-comp-hash))))
+                   ;; FIXME: This lambda probably shouldn't be quoted.
+                   '(lambda () ,@(nth 1 kb))))
+                ergoemacs-theme-comp-hash))))
 
 (declare-function ergoemacs-theme-get-version "ergoemacs-theme-engine.el")
 (declare-function ergoemacs-theme-set-version "ergoemacs-theme-engine.el")
@@ -262,9 +265,9 @@ Uses `ergoemacs-theme-component--parse-keys-and-body' and
          (ergoemacs-theme-set-version old-version)
          (ergoemacs-mode 1)))))
 
-(fset 'ergoemacs-theme-component--parse-keys-and-body
-      #'(lambda (keys-and-body &optional parse-function  skip-first)
-          "Split KEYS-AND-BODY into keyword-and-value pairs and the remaining 
body.
+(defun ergoemacs-theme-component--parse-keys-and-body
+    (keys-and-body &optional parse-function  skip-first)
+  "Split KEYS-AND-BODY into keyword-and-value pairs and the remaining body.
 
 KEYS-AND-BODY should have the form of a property list, with the
 exception that only keywords are permitted as keys and that the
@@ -278,38 +281,38 @@ This has been stolen directly from ert by Christian Ohler 
<address@hidden>
 
 Afterward it was modified for use with `ergoemacs-mode' to use
 additional parsing routines defined by PARSE-FUNCTION."
-          (let ((extracted-key-accu '())
-                plist
-                (remaining keys-and-body))
-            ;; Allow
-            ;; (component name)
-            (unless (or (keywordp (first remaining)) skip-first)
-              (if (condition-case nil
-                      (stringp (first remaining))
-                    (error nil))
-                  (push (cons ':name (pop remaining)) extracted-key-accu)
-                (push (cons ':name  (symbol-name (pop remaining))) 
extracted-key-accu))
-              (when (memq (type-of (first remaining)) '(symbol cons))
-                (setq remaining (cdr remaining)))
-              (when (stringp (first remaining))
-                (push (cons ':description (pop remaining)) 
extracted-key-accu)))
-            (while (and (consp remaining) (keywordp (first remaining)))
-              (let ((keyword (pop remaining)))
-                (unless (consp remaining)
-                  (error "Value expected after keyword %S in %S"
-                         keyword keys-and-body))
-                (when (assoc keyword extracted-key-accu)
-                  (warn "Keyword %S appears more than once in %S" keyword
-                        keys-and-body))
-                (push (cons keyword (pop remaining)) extracted-key-accu)))
-            (setq extracted-key-accu (nreverse extracted-key-accu))
-            (when parse-function
-              (setq remaining
-                    (funcall parse-function remaining)))
-            (setq plist (loop for (key . value) in extracted-key-accu
-                              collect key
-                              collect value))
-            (list plist remaining))))
+  (let ((extracted-key-accu '())
+        plist
+        (remaining keys-and-body))
+    ;; Allow
+    ;; (component name)
+    (unless (or (keywordp (first remaining)) skip-first)
+      (push (cons ':name (if (stringp (first remaining))
+                             (pop remaining)
+                           (symbol-name (pop remaining))))
+            extracted-key-accu)
+      (when (memq (type-of (first remaining)) '(symbol cons))
+        (setq remaining (cdr remaining)))
+      (when (stringp (first remaining))
+        (push (cons ':description (pop remaining))
+              extracted-key-accu)))
+    (while (and (consp remaining) (keywordp (first remaining)))
+      (let ((keyword (pop remaining)))
+        (unless (consp remaining)
+          (error "Value expected after keyword %S in %S"
+                 keyword keys-and-body))
+        (when (assoc keyword extracted-key-accu)
+          (warn "Keyword %S appears more than once in %S" keyword
+                keys-and-body))
+        (push (cons keyword (pop remaining)) extracted-key-accu)))
+    (setq extracted-key-accu (nreverse extracted-key-accu))
+    (when parse-function
+      (setq remaining
+            (funcall parse-function remaining)))
+    (setq plist (loop for (key . value) in extracted-key-accu
+                      collect key
+                      collect value))
+    (list plist remaining)))
 
 ;;;###autoload
 (defmacro ergoemacs-theme (&rest body-and-plist)
@@ -382,16 +385,17 @@ DIFFERENCES are the differences from the layout based on 
the functions.  These a
       ((and (<= 24 emacs-major-version)
             (<= 4 emacs-minor-version))
        'eieio-object-name-string)
-      (t 'object-name-string)) ,obj))
+      (t 'object-name-string))
+    ,obj))
 
 (defmacro ergoemacs-object-set-name-string (obj name)
-  "Compatability fixes for `object-set-name-string' or 
`eieio-object-set-name-string'.
-"
+  "Compatability fixes for `object-set-name-string' or 
`eieio-object-set-name-string'."
   `(,(cond
       ((and (<= 24 emacs-major-version)
             (<= 4 emacs-minor-version))
        'eieio-object-set-name-string)
-      (t 'object-set-name-string)) ,obj ,name))
+      (t 'object-set-name-string))
+    ,obj ,name))
 
 ;;;###autoload
 (defmacro ergoemacs-save-buffer-state (&rest body)
diff --git a/ergoemacs-menus.el b/ergoemacs-menus.el
index e933ae2..cee846f 100644
--- a/ergoemacs-menus.el
+++ b/ergoemacs-menus.el
@@ -57,7 +57,7 @@
       (if (catch 'found-keys
             (dolist (i item)
               (when (eq i ':keys)
-                (throw 'found-keys t))) nil)
+                (throw 'found-keys t))))
           nil
         (ergoemacs-shortcut-for-command (cadddr item)))
     nil))
diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el
index a879153..769a733 100644
--- a/ergoemacs-mode.el
+++ b/ergoemacs-mode.el
@@ -718,7 +718,7 @@ However instead of using M-a `eval-buffer', you could use 
M-a `eb'"
 This is done by checking if this is a command that supports shift selection or 
cua-mode's movement."
   (let ((intf (condition-case err
                   (car (cdr (interactive-form command))))))
-    (and intf (eq (type-of intf) 'string)
+    (and intf (stringp intf)
          (or (eq (get command 'CUA) 'move)
              (string-match "address@hidden" intf)))))
 
diff --git a/ergoemacs-shortcuts.el b/ergoemacs-shortcuts.el
index 254aafd..72d7503 100644
--- a/ergoemacs-shortcuts.el
+++ b/ergoemacs-shortcuts.el
@@ -979,6 +979,7 @@ PRETTY-KEY is the ergoemacs-mode pretty representation of 
the key.
                 (unless ret
                   (setq fn (or (command-remapping fn (point)) fn))
                   (setq ergoemacs-single-command-keys key)
+                  ;; FIXME: Redundancy with ergoemacs-read-key--echo-command!
                   (let (message-log-max)
                     (if (string= pretty-key-undefined pretty-key)
                         (message "%s%s%s" pretty-key
@@ -1257,7 +1258,7 @@ argument prompt.
                                     pretty-key pretty-key-trial)))
                           ;; Found, exit
                           (throw 'ergoemacs-key-trials t))
-                         ((eq (type-of local-fn) 'cons)
+                         ((consp local-fn)
                           (when real-read
                             (push (list type
                                         (listify-key-sequence 
ergoemacs-read-key))
@@ -1311,7 +1312,7 @@ argument prompt.
                                 pretty-key pretty-key-trial)
                           ;; Found, exit
                           (throw 'ergoemacs-key-trials t))
-                         ((eq (type-of local-fn) 'cons)
+                         ((consp local-fn)
                           (when real-read
                             (push (list type
                                         (listify-key-sequence 
ergoemacs-read-key))
@@ -1531,17 +1532,19 @@ Calls the function shortcut key defined in
 This also considers archaic emacs bindings by looking at
 `ergoemacs-where-is-global-hash' (ie bindings that are no longer
 in effect)."
-  (let ((ret (gethash (list function dont-ignore-menu) 
ergoemacs-shortcut-function-binding-hash)))
-    (if ret
-        ret
-      (if dont-ignore-menu
-          (where-is-internal function (current-global-map))
-        (dolist (x (where-is-internal function (current-global-map)))
-          (unless (or (eq 'menu-bar (elt x 0)))
-            (push x ret)))
-        (setq ret (reverse ret)))
-      (puthash (list function dont-ignore-menu) ret 
ergoemacs-shortcut-function-binding-hash)
-      ret)))
+  (let ((ret (gethash (list function dont-ignore-menu)
+                      ergoemacs-shortcut-function-binding-hash)))
+    (or ret
+        (progn
+          (if dont-ignore-menu
+              (where-is-internal function (current-global-map))
+            (dolist (x (where-is-internal function (current-global-map)))
+              (unless (or (eq 'menu-bar (elt x 0)))
+                (push x ret)))
+            (setq ret (nreverse ret)))
+          (puthash (list function dont-ignore-menu) ret
+                   ergoemacs-shortcut-function-binding-hash)
+          ret))))
 
 (defcustom ergoemacs-use-function-remapping t
   "Uses function remapping.
@@ -1639,7 +1642,7 @@ user-defined keys.
                   (when fn
                     (cond
                      ((eq ignore-desc t))
-                     ((eq (type-of ignore-desc) 'string)
+                     ((stringp ignore-desc)
                       (when (string-match ignore-desc key-desc)
                         (setq fn nil)))
                      (t
diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el
index 3e218ec..6c0b922 100644
--- a/ergoemacs-theme-engine.el
+++ b/ergoemacs-theme-engine.el
@@ -51,12 +51,10 @@
 ;; 
 ;;; Code:
 
-(eval-when-compile 
+(eval-when-compile
   (require 'cl)
   (require 'ergoemacs-macros))
 
-;;; Not sure why `adjoin' may be called at run-time; sigh.
-(autoload 'adjoin "cl.el")
 
 (defgroup ergoemacs-themes nil
   "Default Ergoemacs Layout"
@@ -325,8 +323,8 @@ The elements of LIST are not copied, just the list 
structure itself."
                  modify-map
                  deferred-keys
                  full-map) obj
-      (ergoemacs-debug "%s %s" (or (and (string= stars "") "Keymap:")
-                                   stars) object-name)
+      (ergoemacs-debug "%s %s" (or (and (string= stars "") "Keymap:") stars)
+                       object-name)
       (ergoemacs-debug "Deferred Keys: %s" deferred-keys)
       (cond
        ((ergoemacs-keymap-empty-p read-map)
@@ -1750,9 +1748,9 @@ The actual keymap changes are included in 
`ergoemacs-emulation-mode-map-alist'."
             (unless (member (nth 0 c) rm-list)
               (puthash (nth 0 c) (nth 1 c) ergoemacs-command-shortcuts-hash)
               (when (< 1 (length (nth 0 c)))
-                (pushnew (substring (nth 0 c) 0 -1)
-                         ergoemacs-shortcut-prefix-keys
-                         :test 'equal))
+                (let ((k (substring (nth 0 c) 0 -1)))
+                  ;; Warning: `k' here avoids need for `adjoin' in Emacs≤24.3.
+                  (pushnew k ergoemacs-shortcut-prefix-keys :test 'equal)))
               (when (eq (nth 1 (nth 1 c)) 'global)
                 (dolist (global-key (ergoemacs-shortcut-function-binding (nth 
0 (nth 1 c))))
                   (if (not (gethash global-key 
ergoemacs-original-keys-to-shortcut-keys))
@@ -2289,9 +2287,9 @@ DONT-COLLAPSE doesn't collapse empty keymaps"
             (maphash
              (lambda(key _ignore)
                (when (< 1 (length key))
-                 (pushnew (substring key 0 -1)
-                          ergoemacs-shortcut-prefix-keys
-                          :test 'equal)))
+                 (let ((k (substring key 0 -1)))
+                   ;; Warning: `k' here avoids need for `adjoin' in Emacs≤24.3.
+                   (pushnew k ergoemacs-shortcut-prefix-keys :test 'equal))))
              ergoemacs-command-shortcuts-hash)
             ;; Setup emulation maps.
             (setq ergoemacs-read-emulation-mode-map-alist
@@ -2322,7 +2320,7 @@ DONT-COLLAPSE doesn't collapse empty keymaps"
   (ergoemacs-get-versions (ergoemacs-theme-get-obj theme version)))
 
 (defun ergoemacs-theme-set-version (version)
-  "Sets the current themes default VERSION"
+  "Set the current themes default VERSION."
   (let (found)
     (setq ergoemacs-theme-version
           (mapcar
@@ -2336,7 +2334,7 @@ DONT-COLLAPSE doesn't collapse empty keymaps"
       (push (list (or ergoemacs-theme "standard") version) 
ergoemacs-theme-version))))
 
 (defun ergoemacs-theme-get-version ()
-  "Gets the current version for the current theme"
+  "Get the current version for the current theme."
   (let ((theme-ver (assoc (or ergoemacs-theme "standard") 
ergoemacs-theme-version)))
     (if (not theme-ver) nil
       (car (cdr theme-ver)))))
@@ -2389,13 +2387,14 @@ and it dosen't show up on the ergoemacs-mode menu.
 TYPE can also be 'off, where the option will be included in the
 theme, but assumed to be disabled by default.
 "
-  (if (eq (type-of option) 'cons)
+  (if (consp option)
       (dolist (new-option option)
         (let (ergoemacs-mode)
           (ergoemacs-require new-option theme type)))
     (let ((option-sym
            (or (and (stringp option) (intern option)) option)))
-      (dolist (theme (or (and theme (or (and (eq (type-of theme) 'cons) theme) 
(list theme)))
+      (dolist (theme (or (and theme (if (consp theme) theme
+                                      (list theme)))
                          (ergoemacs-get-themes)))
         (let ((theme-plist (gethash (if (stringp theme) theme
                                       (symbol-name theme))
@@ -2427,7 +2426,7 @@ theme, but assumed to be disabled by default.
   "Turns OPTION on.
 When OPTION is a list turn on all the options in the list
 If OFF is non-nil, turn off the options instead."
-  (if (eq (type-of option) 'cons)
+  (if (consp option)
       (dolist (new-option option)
         (let (ergoemacs-mode)
           (ergoemacs-theme-option-on new-option off)))
@@ -2618,8 +2617,7 @@ If OFF is non-nil, turn off the options instead."
        (lambda()
          (interactive)
          (set-default 'ergoemacs-smart-paste 'browse-kill-ring))
-       :enable (condition-case err (interactive-form 'browse-kill-ring)
-                 (error nil))
+       :enable (commandp 'browse-kill-ring)
        :button (:radio . (eq ergoemacs-smart-paste 'browse-kill-ring)))))
     (ergoemacs-sep-bash "--")
     (ergoemacs-bash
@@ -2807,7 +2805,8 @@ Ignores _DESC."
         (ergoemacs-define-key 'global-map key function))
     (warn "ergoemacs-fixed-key is depreciated, use global-set-key instead.")
     (global-set-key (if (vectorp key) key
-                      (read-kbd-macro key)) function)))
+                      (read-kbd-macro key))
+                    function)))
 
 (provide 'ergoemacs-theme-engine)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el
index 36ae52d..1fa52cd 100644
--- a/ergoemacs-themes.el
+++ b/ergoemacs-themes.el
@@ -27,7 +27,7 @@
 ;; 
 
 ;;; Code:
-(eval-when-compile 
+(eval-when-compile
   (require 'cl)
   (require 'ergoemacs-macros))
 
diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el
index 8288765..b3da6cc 100644
--- a/ergoemacs-translate.el
+++ b/ergoemacs-translate.el
@@ -1,6 +1,6 @@
 ;;; ergoemacs-translate.el --- Keyboard translation functions -*- 
lexical-binding: t -*-
 
-;; Copyright © 2013-2014  Free Software Foundation, Inc.
+;; Copyright © 2013-2015  Free Software Foundation, Inc.
 
 ;; Filename: ergoemacs-translate.el
 ;; Description: 
@@ -139,7 +139,9 @@ This assumes `ergoemacs-use-unicode-char' is non-nil.  When
         (let* ((ob (or (and ergoemacs-use-unicode-brackets 
(ergoemacs-unicode-char "【" "[")) "["))
                (cb (or (and ergoemacs-use-unicode-brackets 
(ergoemacs-unicode-char "】" "]")) "]"))
                (ret (concat ob (replace-regexp-in-string
-                                " +$" "" (replace-regexp-in-string "^ +" "" 
code)) cb))
+                                " +\\'" ""
+                                (replace-regexp-in-string "\\` +" "" code))
+                            cb))
                (case-fold-search nil)
                (pt 0))
           (when ergoemacs-use-ergoemacs-key-descriptions
@@ -351,46 +353,45 @@ This keymap is made in `ergoemacs-translation'"))))
 This keymap is made in `ergoemacs-translation'"))))
     
     ;; Create the universal argument functions.
-    (eval (macroexpand
-           `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-universal-argument")) ()
-              ,(concat "Ergoemacs universal argument, with "
-                       (symbol-name (plist-get arg-plist ':name))
-                       " translation setup.
+    ;; FIXME: Since Emacs-25 we could use a closure with a computed docstring,
+    ;; using (:documentation <exp>).
+    (eval `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-universal-argument")) ()
+             ,(concat "Ergoemacs universal argument, with "
+                      (symbol-name (plist-get arg-plist ':name))
+                      " translation setup.
 This is called through `ergoemacs-universal-argument'.
 This function is made in `ergoemacs-translation'")
-              (interactive)
-              (ergoemacs-universal-argument ',(plist-get arg-plist ':name)))))
-    (add-to-list 'ergoemacs-universal-fns
-                 (intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-universal-argument")))
-
-    (eval (macroexpand
-           `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-digit-argument")) ()
-              ,(concat "Ergoemacs digit argument, with "
-                       (symbol-name (plist-get arg-plist ':name))
-                       " translation setup.
+             (interactive)
+             (ergoemacs-universal-argument ',(plist-get arg-plist ':name))))
+    (pushnew (intern (format "ergoemacs-%s-universal-argument"
+                             (plist-get arg-plist ':name)))
+             ergoemacs-universal-fns)
+
+    (eval `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-digit-argument")) ()
+             ,(concat "Ergoemacs digit argument, with "
+                      (symbol-name (plist-get arg-plist ':name))
+                      " translation setup.
 This is called through `ergoemacs-digit-argument'.
 This function is made in `ergoemacs-translation'")
-              (interactive)
-              (ergoemacs-digit-argument ',(plist-get arg-plist ':name)))))
+             (interactive)
+             (ergoemacs-digit-argument ',(plist-get arg-plist ':name))))
 
-    (eval (macroexpand
-           `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-negative-argument")) ()
+    (eval `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-negative-argument")) ()
               ,(concat "Ergoemacs digit argument, with "
                        (symbol-name (plist-get arg-plist ':name))
                        " translation setup.
 This is called through `ergoemacs-negative-argument'.
 This function is made in `ergoemacs-translation'")
               (interactive)
-              (ergoemacs-negative-argument ',(plist-get arg-plist ':name)))))
+              (ergoemacs-negative-argument ',(plist-get arg-plist ':name))))
 
-    (eval (macroexpand
-           `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-modal")) ()
-              ,(concat "Toggle modal "
-                       (symbol-name (plist-get arg-plist ':name))
-                       " translation.
+    (eval `(defun ,(intern (concat "ergoemacs-" (symbol-name (plist-get 
arg-plist ':name)) "-modal")) ()
+             ,(concat "Toggle modal "
+                      (symbol-name (plist-get arg-plist ':name))
+                      " translation.
 This function is made in `ergoemacs-translation' and calls 
`ergoemacs-modal-toggle'.")
-              (interactive)
-              (ergoemacs-modal-toggle ',(plist-get arg-plist ':name)))))
+             (interactive)
+             (ergoemacs-modal-toggle ',(plist-get arg-plist ':name))))
     
     
     ;; Now put the translation text together as a list.
@@ -784,19 +785,16 @@ and `ergoemacs-pretty-key' descriptions.
     (while (< i 60)
       (unless (or (string= "" (nth i lay))
                   (string= "" (nth (+ i 60) lay)))
-        ;; Add to list is incompatible with lexical scoping.  However
-        ;; this use is OK since `ergoemacs-shifted-assoc' is defined
-        ;; in a defvar statement.
-        (add-to-list 'ergoemacs-shifted-assoc
-                     `(,(nth i lay) . ,(nth (+ i 60) lay)))
-        (add-to-list 'ergoemacs-shifted-assoc
-                     `(,(nth (+ i 60) lay) . ,(nth i lay)))
-        (pushnew (nth i lay)
-                 unshifted-list
-                 :test 'equal)
-        (pushnew (nth (+ i 60) lay)
-                 shifted-list
-                 :test 'equal))
+        (let* ((u (nth i lay))
+               (s (nth (+ i 60) lay))
+               (sa1 `(,u . ,s))
+               (sa2 `(,s . ,u)))
+          ;; Warning: We use local vars here to avoid optimization bug in
+          ;; pushnew in Emacs≤24.3 which would make it use `adjoin'.
+          (pushnew sa1 ergoemacs-shifted-assoc :test 'equal)
+          (pushnew sa2 ergoemacs-shifted-assoc :test 'equal)
+          (pushnew u unshifted-list :test 'equal)
+          (pushnew s shifted-list :test 'equal)))
       (setq i (+ i 1)))
     (setq ergoemacs-shifted-regexp 
           (format "\\(-\\| \\|^\\)\\(%s\\)\\($\\| \\)"
@@ -822,13 +820,14 @@ and `ergoemacs-pretty-key' descriptions.
         (while (< i len)
           (unless (or (string= "" (nth i base))
                       (string= "" (nth i lay)))
-            (add-to-list 'ergoemacs-translation-assoc
-                         `(,(nth i base) . ,(nth i lay))))
+            (let ((ta `(,(nth i base) . ,(nth i lay))))
+              ;; Warning: `ta' here avoids need for `adjoin' in Emacs≤24.3.
+              (pushnew ta ergoemacs-translation-assoc :test 'equal)))
           (setq i (+ i 1)))
         (setq ergoemacs-translation-regexp
               (format "\\(-\\| \\|^\\)\\(%s\\)\\($\\| \\)"
                       (regexp-opt (mapcar (lambda(x) (nth 0 x))
-                                          ergoemacs-translation-assoc) nil)))))
+                                          ergoemacs-translation-assoc))))))
     ;; Pre-cache the translations...?  Takes too long to load :(
     (when nil
       (dolist (char (append lay '("<f1>"  "<S-f1>"
diff --git a/ergoemacs-unbind.el b/ergoemacs-unbind.el
index 16b38a6..f868db0 100644
--- a/ergoemacs-unbind.el
+++ b/ergoemacs-unbind.el
@@ -28,10 +28,9 @@
 ;; 
 
 ;;; Code:
-(eval-when-compile 
+(eval-when-compile
   (require 'cl)
   (require 'ergoemacs-macros))
-
 (require 'edmacro)
 
 (defvar ergoemacs-emacs-default-bindings
@@ -647,7 +646,8 @@
 (defun ergoemacs-undefined ()
   "Ergoemacs Undefined key, echo new key for old action."
   (interactive)
-  (let* ((key-kbd (or ergoemacs-single-command-keys 
(this-single-command-keys)))
+  (let* ((key-kbd (or ergoemacs-single-command-keys
+                      (this-single-command-keys)))
          tmp
          (local-fn nil))
     ;; Lookup local key, if present and then issue that
@@ -667,22 +667,21 @@
       (setq tmp (ergoemacs-real-key-binding key-kbd))
       (when (and tmp (not (equal tmp 'ergoemacs-undefined)))
         (setq local-fn tmp))
-      (when (featurep 'keyfreq)
-        (when keyfreq-mode
-          (let ((command 'ergoemacs-undefined) count)
-            (setq count (gethash (cons major-mode command) keyfreq-table))
-            (cond
-             ((not count))
-             ((= count 1)
-              (remhash (cons major-mode command) keyfreq-table))
-             (count
-              (puthash (cons major-mode command) (- count 1)
-                       keyfreq-table)))
-            ;; Add local-fn to counter.
-            (setq command local-fn)
-            (setq count (gethash (cons major-mode command) keyfreq-table))
-            (puthash (cons major-mode command) (if count (+ count 1) 1)
-                     keyfreq-table))))
+      (when (and (boundp 'keyfreq-mode) keyfreq-mode (boundp 'keyfreq-table))
+        (let* ((command 'ergoemacs-undefined)
+               (count (gethash (cons major-mode command) keyfreq-table)))
+          (cond
+           ((not count))
+           ((= count 1)
+            (remhash (cons major-mode command) keyfreq-table))
+           (count
+            (puthash (cons major-mode command) (- count 1)
+                     keyfreq-table)))
+          ;; Add local-fn to counter.
+          (setq command local-fn)
+          (setq count (gethash (cons major-mode command) keyfreq-table))
+          (puthash (cons major-mode command) (if count (+ count 1) 1)
+                   keyfreq-table)))
       (setq this-command local-fn)
       (condition-case err
           (call-interactively local-fn)
@@ -691,30 +690,28 @@
         ;; Local map present.  Use it, if there is a key
         ;; defined there.
         (setq local-fn (get-char-property (point) 'local-map))
-        (if (and local-fn
-                 (ignore-errors (keymapp local-fn)))
+        (if (and local-fn (keymapp local-fn))
             (setq local-fn (lookup-key local-fn key-kbd))
           (if (current-local-map)
               (setq local-fn (lookup-key (current-local-map) key-kbd))
             (setq local-fn nil)))
         (functionp local-fn))
       (setq this-command local-fn) ; Don't record this command.
-      (when (featurep 'keyfreq)
-        (when keyfreq-mode
-          (let ((command 'ergoemacs-undefined) count)
-            (setq count (gethash (cons major-mode command) keyfreq-table))
-            (cond
-             ((not count))
-             ((= count 1)
-              (remhash (cons major-mode command) keyfreq-table))
-             (count
-              (puthash (cons major-mode command) (- count 1)
-                       keyfreq-table)))
-            ;; Add local-fn to counter.
-            (setq command local-fn)
-            (setq count (gethash (cons major-mode command) keyfreq-table))
-            (puthash (cons major-mode command) (if count (+ count 1) 1)
-                     keyfreq-table))))
+      (when (and (boundp 'keyfreq-mode) keyfreq-mode (boundp 'keyfreq-table))
+        (let ((command 'ergoemacs-undefined) count)
+          (setq count (gethash (cons major-mode command) keyfreq-table))
+          (cond
+           ((not count))
+           ((= count 1)
+            (remhash (cons major-mode command) keyfreq-table))
+           (count
+            (puthash (cons major-mode command) (- count 1)
+                     keyfreq-table)))
+          ;; Add local-fn to counter.
+          (setq command local-fn)
+          (setq count (gethash (cons major-mode command) keyfreq-table))
+          (puthash (cons major-mode command) (if count (+ count 1) 1)
+                   keyfreq-table)))
       (condition-case err
           (call-interactively local-fn)
         (error (beep) (message "%s" err))))
@@ -745,10 +742,9 @@
   (setq ergoemacs-emacs-default-bindings
         (mapcar
          (lambda(elt)
-           (let ((first (nth 0  elt))
-                 (last (nth 1 elt))
-                 fn)
-             (setq fn (lookup-key global-map (read-kbd-macro first)))
+           (let* ((first (nth 0  elt))
+                  (last (nth 1 elt))
+                  (fn (lookup-key global-map (read-kbd-macro first))))
              (if (not (functionp fn))
                  elt
                (pushnew fn last :test 'equal)
@@ -779,7 +775,7 @@
   "Cache of global variables that have changed.")
 
 (defvar ergoemacs-dir)
-(defun ergoemacs-global-fix-defualt-bindings (kbd-code function)
+(defun ergoemacs-global-fix-default-bindings (kbd-code function)
   "Helper function to fix `ergoemacs-emacs-default-bindings' based on 
currently running emacs."
   (interactive)
   (with-temp-buffer
@@ -803,13 +799,14 @@ This should only be run when no global keys have been set.
 "
   (let* ((key-code
           (cond
-           ((eq (type-of key) 'string)
+           ((stringp key)
             (if is-variable
                 (ergoemacs-kbd key)
-              (or (ignore-errors (read-kbd-macro key))
-                  (read-kbd-macro
-                   (encode-coding-string
-                    key locale-coding-system)))))
+              (condition-case nil
+                  (read-kbd-macro key)
+                (error (read-kbd-macro
+                        (encode-coding-string
+                         key locale-coding-system))))))
            (t key)))
          (key-kbd (key-description key-code)))
     (if (string-match "\\(mouse\\|wheel\\)" key-kbd)
@@ -819,7 +816,7 @@ This should only be run when no global keys have been set.
             (when (or fix complain)
               (let* ((key-function (lookup-key (current-global-map) key-code 
t))
                      (old-bindings (assoc key-kbd 
ergoemacs-emacs-default-bindings))
-                     (trans-function (if (ignore-errors (keymapp key-function))
+                     (trans-function (if (keymapp key-function)
                                          'prefix
                                        key-function)))
                 (message "Warning %s has been set globally. It is bound to %s 
not in %s." key-kbd
@@ -829,7 +826,7 @@ This should only be run when no global keys have been set.
             nil
           (let* ((key-function (lookup-key (current-global-map) key-code t))
                  (old-bindings (assoc key-kbd 
ergoemacs-emacs-default-bindings))
-                 (trans-function (if (ignore-errors (keymapp key-function))
+                 (trans-function (if (keymapp key-function)
                                      'prefix
                                    key-function))
                  (has-changed nil))
@@ -845,17 +842,17 @@ This should only be run when no global keys have been set.
                   (setq i (+ 1 i)))
                 ;; If it is a prefix vector, assume not globally
                 ;; changed
-                (unless (ignore-errors (keymapp (lookup-key 
(current-global-map) prefix-vector)))
+                (unless (keymapp (lookup-key (current-global-map) 
prefix-vector))
                   ;; Not a prefix, see if the key had actually changed
                   ;; by recursively calling `ergoemacs-global-changed-p'
                   (setq has-changed
                         (ergoemacs-global-changed-p
                          prefix-vector is-variable complain fix)))))
-             (old-bindings ; Trans function is defined, not an integer
+             (old-bindings ; Trans function is defined, not an integer.
               (unless (member trans-function (nth 1 old-bindings))
                 (setq has-changed t)))
              (t
-              (setq has-changed t)) ; Not found in old bindings, but bound 
globally
+              (setq has-changed t)) ; Not found in old bindings, but bound 
globally.
              )
             (if has-changed
                 (progn
@@ -864,24 +861,27 @@ This should only be run when no global keys have been set.
                              trans-function old-bindings)
                     (when fix
                       (unless (integerp trans-function)
-                        (ergoemacs-global-fix-defualt-bindings key-kbd 
trans-function))))
-                  (pushnew key-kbd ergoemacs-global-changed-cache :test 
'equal))
-              (pushnew key-kbd ergoemacs-global-not-changed-cache :test 
'equal))
+                        (ergoemacs-global-fix-default-bindings
+                         key-kbd trans-function))))
+                  (pushnew key-kbd ergoemacs-global-changed-cache
+                           :test 'equal))
+              (pushnew key-kbd ergoemacs-global-not-changed-cache
+                       :test 'equal))
             has-changed))))))
 
 (declare-function ergoemacs-get-fixed-layout "ergoemacs-translate.el")
 (declare-function ergoemacs-get-variable-layout "ergoemacs-translate.el")
 (defun ergoemacs-warn-globally-changed-keys (&optional fix)
-  "Warns about globally changed keys. If FIX is true, fix the ergoemacs-unbind 
file."
+  "Warn about globally changed keys. If FIX is true, fix the ergoemacs-unbind 
file."
   (interactive)
   (dolist (x ergoemacs-emacs-default-bindings)
     (ergoemacs-global-changed-p (nth 0 x) nil t fix))
   (message "Ergoemacs Keys warnings for this layout:")
   (dolist (x (symbol-value (ergoemacs-get-fixed-layout)))
-    (and (eq 'string (type-of (nth 0 x)))
+    (and (stringp (nth 0 x))
          (ergoemacs-global-changed-p (nth 0 x) nil t fix)))
   (dolist (x (symbol-value (ergoemacs-get-variable-layout)))
-    (and (eq 'string (type-of (nth 0 x)))
+    (and (stringp (nth 0 x))
          (ergoemacs-global-changed-p (nth 0 x) t t fix))))
 
 



reply via email to

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