Error with minor-mode in emacs 24 on macbook

60 Views Asked by At

This was the function I had found online somewhere and never had problems in linux but when run on a macbook in emacs 24 I get the error below. Any help would be appreciated.

;; (define-minor-mode sensitive-mode
;;   "For sensitive files like password lists.
;; It disables backup creation and auto saving.

;; With no argument, this command toggles the mode.
;; Non-null prefix argument turns on the mode.
;; Null prefix argument turns off the mode."
;;   ;; The initial value.
;;   -1
;;   ;; The indicator for the mode line.
;;   " Sensitive"
;;   ;; The minor mode bindings.
;;   -1
;;   (if (symbol-value sensitive-mode)
;;       (progn
;;  ;; disable backups
;;  (set (make-local-variable 'backup-inhibited) 1) 
;;  ;; disable auto-save
;;  (if auto-save-default
;;      (auto-save-mode -1)))
;;     ;resort to default value of backup-inhibited
;;     (kill-local-variable 'backup-inhibited)
;;     ;resort to default auto save setting
;;     (if auto-save-default
;;  (auto-save-mode 1))))
;; (setq auto-mode-alist
;;  (append '(("\\.gpg$" . sensitive-mode))
;;                auto-mode-alist))

The error is:

Debugger entered--Lisp error: (error "Invalid keymap -1")
2    signal(error ("Invalid keymap -1"))
3    error("Invalid keymap %S" -1)
4    (cond ((keymapp m) m) ((listp m) (easy-mmode-define-keymap m)) (t (error "Invalid keymap %S" m)))
5    (let ((m -1)) (cond ((keymapp m) m) ((listp m) (easy-mmode-define-keymap m)) (t (error "Invalid keymap %S" m))))
6    (defvar sensitive-mode-map (let ((m -1)) (cond ((keymapp m) m) ((listp m) (easy-mmode-define-keymap m)) (t (error "$
7    (progn (progn :autoload-end (defvar sensitive-mode -1 "Non-nil if Sensitive mode is enabled.\nUse the command `sens$
8    eval-buffer(#<buffer  *load*-983931> nil "/Users/bigtyme/Dropbox/SyncedPrograms/emacs/initFiles/setup.el" nil t)  ;$
9    load-with-code-conversion("/Users/bigtyme/Dropbox/SyncedPrograms/emacs/initFiles/setup.el" "/Users/bigtyme/Dropbox/$
10   load("/Users/bigtyme/Dropbox/SyncedPrograms/emacs/initFiles/setup.el" nil nil t)
11   load-file("~/Dropbox/SyncedPrograms/emacs/initFiles/setup.el")
12   eval-buffer(#<buffer  *load*> nil "/Users/bigtyme/.emacs" nil t)  ; Reading at buffer position 2000
13   load-with-code-conversion("/Users/bigtyme/.emacs" "/Users/bigtyme/.emacs" t t)
14   load("~/.emacs" t t)
15   #[0 "^H\205\262^@     \306=\203^Q^@\307^H\310Q\202;^@ \311=\204^^^@\307^H\312Q\202;^@\313\307\314\315#\203*^@\316\2$
16   command-line()
17   normal-top-level()
2

There are 2 best solutions below

0
Drew On

Show the code that defines the minor mode (uncommented). Show any code that binds keys in the minor mode's keymap. The error you show does not relate directly to the code you show.

In particular, show the defvar that defines the keymap sensitive-mode-map. It is that defvar sexp that seems to be the problem.

This is the code used by the defvar, apparently:

(let ((m -1))
   (cond ((keymapp m) m)
         ((listp m) (easy-mmode-define-keymap m))
         (t (error "Invalid keymap %S" m)))

And clearly that binding of m to -1 means that the 3rd cond clause is evaluated. This could never have worked on any Emacs platform, IMO --- UNLESS your init file or some other code actually set the value of that keymap prior to that defvar being evaluated. In that case, the defvar would do nothing.

0
Carl Groner On

The 5th parameter to define-minor-mode is expected to be a keymap, where your example is passing the value -1.

You should change it to nil if you don't have a keymap.

...
;; The minor mode bindings.
nil                                  ;; Not -1
(if (symbol-value sensitive-mode)
...

Also, passing -1 as the init-value doesn't really make sense either, that should generally also be nil.