0

When I load emacs, it gives me this error using --debug-init after adding cl-lib.el:

Debugger entered--Lisp error: (void-function gv-define-simple-setter)
  (gv-define-simple-setter buffer-file-name set-visited-file-name t)
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil t)  ; Reading at buffer position 23391
  load-with-code-conversion("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil nil)
  load("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el")
  mapc(load ("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 76
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

This is the gv.el file I am using:

https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/gv.el

Does anyone have any suggestions? TIA.

UPDATE:

Here is the original error I was getting:

Debugger entered--Lisp error: (file-error "Cannot open load file" "cl-lib")
  require(cl-lib)
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil t)  ; Reading at buffer position 5870
  load-with-code-conversion("d:/Tools/emacs-24.3/site-lisp/desktop.el" "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil nil)
  load("d:/Tools/emacs-24.3/site-lisp/desktop.el")
  mapc(load ("d:/Tools/emacs-24.3/site-lisp/desktop.el"))
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 549
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

Here is my .emacs file:

(mapc 'load (file-expand-wildcards "D:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))

;; Require Common Lisp. (cl in <=24.2, cl-lib in >=24.3.)
(if (require 'cl-lib nil t)
  (progn
    (defalias 'cl-block-wrapper 'identity)
    (defalias 'member* 'cl-member)
    (defalias 'adjoin 'cl-adjoin))
  ;; Else we're on an older version so require cl.
  (require 'cl))

;; Load lisp files on start
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/session.el"))

;; setup load-path
(add-to-list 'load-path "D:/Tools/emacs-24.3/site-lisp")

;; TABS for C
(setq-default c-indent-tabs-mode t     ; Pressing TAB should cause indentation
                c-indent-level 4         ; A TAB is equivilent to four spaces
                c-argdecl-indent 0       ; Do not indent argument decl's extra
                c-tab-always-indent t
                backward-delete-function nil) ; DO NOT expand tabs when deleting
  (c-add-style "my-c-style" '((c-continued-statement-offset 4))) ; If a statement continues on the next line, indent the continuation by 4
  (defun my-c-mode-hook ()
    (c-set-style "my-c-style")
    (c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
    (c-set-offset 'inline-open '+)
    (c-set-offset 'block-open '+)
    (c-set-offset 'brace-list-open '+)   ; all "opens" should be indented by the c-indent-level
    (c-set-offset 'case-label '+))       ; indent case labels by c-indent-level, too
(require 'csharp-mode)
(setq auto-mode-alist
      (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
  "function that runs when csharp-mode is initialized for a buffer."
  (setq default-tab-width 4)
  ; Set indentation level to 4 spaces (instead of 2)
  (setq c-basic-offset 4)
  ; Set the extra indentation before a substatement (e.g. the opening brace in
  ; the consequent block of an if statement) to 0 (instead of '+)
  (c-set-offset 'substatement-open 0)
  (setq-default c-basic-offset 4)
)
(add-hook  'csharp-mode-hook 'my-csharp-mode-fn t)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)

(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-cy" '(lambda ()
                         (interactive)
                         (popup-menu 'yank-menu)))
(put 'upcase-region 'disabled nil)
;; Always use spaces instead of tabs
(setq-default indent-tabs-mode nil)

(defun FindNextDbl ()
  "move to next doubled word, ignoring <...> tags" (interactive)
  (re-search-forward "\\<\\([z-z]+\\)\\([\\n \\t]\\|<[^>]+>\\)+\\1\\?"))

(define-key global-map "\C-x\C-d" 'FindNextDbl)

;; Search all open buffers
(defun my-multi-occur-in-matching-buffers (regexp &optional allbufs)
  "Show all lines matching REGEXP in all buffers."
  (interactive (occur-read-primary-args))
  (multi-occur-in-matching-buffers ".*" regexp))
(global-set-key (kbd "M-s /") 'my-multi-occur-in-matching-buffers)

(setq x-select-enable-clipboard t)

;; Copy list of all open buffers to clipboard: see http://stackoverflow.com/questions/10537265/emacs-save-current-buffer-list-to-a-text-file
(defun copy-open-files ()
  "Add paths to all open files to kill ring"
  (interactive)
  (kill-new (mapconcat 'identity
                       (delq nil (mapcar 'buffer-file-name (buffer-list)))
                       "\n"))
  (message "List of files copied to kill ring"))

;; save my desktop
(desktop-save-mode 1)

;; auto-reload modified files
(global-auto-revert-mode t)

;; put save files in back dir (see http://www.emacswiki.org/emacs/BackupDirectory)
(setq
   backup-by-copying t      ; don't clobber symlinks
   backup-directory-alist
    '(("." . "~/.saves"))    ; don't litter my fs tree
   delete-old-versions t
   kept-new-versions 6
   kept-old-versions 2
   version-control t)       ; use versioned backups

;; move to window based on arrow keys
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)

;; incremental completion
(require 'helm-config)
(helm-mode 1)

;; http://stackoverflow.com/questions/275842/is-there-a-repeat-last-command-in-emacs
(defun describe-last-function()
  (interactive)
  (describe-function last-command))

;; get path of present buffer, see http://stackoverflow.com/questions/3669511/the-function-to-show-current-files-full-path-in-mini-buffer
(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name)))

(global-set-key [C-f1] 'show-file-name) ; Or any other key you want

;; generate guids
(require 'guid)

UPDATE 2:

Thank you for the excellent post, @Thomas. This is what I've updated the start of my .emacs file to:

;; setup load-path
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp/gv.el")
(require 'gv)
(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp")

;; Load lisp files on start
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/session.el"))

Now this is the error I'm getting:

Debugger entered--Lisp error: (void-variable defun-declarations-alist)
  (assq (quote gv-expander) defun-declarations-alist)
  (or (assq (quote gv-expander) defun-declarations-alist) (let ((x (\` (gv-expander (\, (apply-partially ... ...)))))) (push x macro-declarations-alist) (push x defun-declarations-alist)))
  eval-buffer(#<buffer  *load*<2>> nil "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t)  ; Reading at buffer position 8332
  load-with-code-conversion("d:/Tools/Emacs-24.3/site-lisp/gv.el" "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t)
  require(gv)
  eval-buffer(#<buffer  *load*> nil "c:/Users/Psalm3_3/.emacs" nil t)  ; Reading at buffer position 96
  load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

Sorry, I'm pretty new at LISP.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
user8128167
  • 6,929
  • 6
  • 66
  • 79
  • It's a little more complicated than just throwing in your favorite `gv.el` from an arbitrary Emacs version. Pick a complete version of Emacs that is supported by your favorite packages -- e.g, whatever helm supports. – lawlist Feb 19 '16 at 07:26
  • Right now I'm using emacs 24.3. Helm worked no problem at my contract job for 5 months, but now that I'm finished my contract I'm trying to get it working at home on Windows 10 using the same .emacs and site-lisp files, but am having trouble. At my contract job on Windows 7 emacs never complained about cl-lib. – user8128167 Feb 19 '16 at 16:21

2 Answers2

1

The error stems from Emacs not being able to load the right files. You're trying to load a bunch of single files manually here. However, this is not the way the underlying packages are supposed to be loaded.

Usually, packages come with installation instructions that typically require you to add some lines to your init file: amending the load-path, setting up conditions for when to load the package, and adding a command how to load the package. Hardly ever does any of this ever involve a direct call of the load function which is quite low-level.

If you look at your original error, the stack trace tells you that it's thrown by (require cl-lib). require is one of the mechanisms by which Emacs loads files when necessary. For it to work, you don't need to load the file in question directly. All you have to do is set up your load-path so that Emacs can find the file that is referred to.

For instance, for your cl-lib.el file, you could do this like so:

(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")

You add this line to your init file (and of course at a point before Emacs tries to load cl-lib).

The counter-part to require is provide. If you look at source code for gv.el and scroll all the way to the bottom, you'll find as the last line:

(provide 'gv)

This means that his file provides the "feature" gv, and whenever you write (require 'gv) you're telling Emacs that you need that feature. If Emacs already knows about it, all is fine and dandy; if not, Emacs will try to load that feature. So, to load the contents of the gv.el file, all you have to do is add the following to your init file:

(add-to-list 'load-path "/path/to/directory/containing/gv.el")
(require 'gv)

See the Emacs Manual for more information on require and provide.

But let me reiterate one point from above: usually, packages come with specific installation instructions, often somewhat "hidden" in a long comment-section at the top of the source code file. So, make sure to check for such instructions whenever you want to manually add a package to your setup.


On a side note:

(mapc 'load <something>)

only really makes sense if <something> expands into a list of files. If, like in your case, <something> is just a single file, you might as well just write:

(load <something>)

But again, load is a low-level function that you hardly ever need as an end-user.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Thomas
  • 17,016
  • 4
  • 46
  • 70
1

The code you have for cl-lib looks very weird. If you have Emacs≥24.3 then you already have cl-lib builtin. And if you have something older then you can't use Emacs-24.3's cl-lib (you have to use GNU ELPA's cl-lib instead, but if it's sufficiently older you won't have GNU ELPA support builtin either, so all in all you're better up upgrading your Emacs to 24.3 or more recent).

If your Emacs is 24,1 or 24.2, then I recommend you just install cl-lib via M-x package-install RET and then add

(package-initialize)

at the beginning of your ~/.emacs which will properly setup autoloads for those packages you install via package.el (such as cl-lib above).

The block that starts with (if (require 'cl-lib ...) ...) looks like an ugly hack to work around a problem you mis-understood. Just remove it.

Also, remove flymake.el and desktop.el from your site-lisp, the version that comes with Emacs is probably more up-to-date.

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • Removed the "if (require 'cl-lib')..., flymake.el and desktop.el, but still getting the same error. – user8128167 Feb 20 '16 at 02:09
  • Also, when I type M-x package-install RET and then type cl-lib, it says "[No match]" – user8128167 Feb 20 '16 at 02:11
  • Have you touched `package-archives` by any chance? Or did you get some failure when fetching the list of packages from elpa.gnu.org (which has been having problems today)? – Stefan Feb 20 '16 at 02:17
  • I haven't touched package-archives intentionally. Also, this is where I got the idea for the "if (require 'cl-lib..." http://williambert.online/2013/05/emacs-cl-lib-madness/ – user8128167 Feb 20 '16 at 02:19
  • Do I need to run emacs as administrator on Windows 10 to get the package-install to work? – user8128167 Feb 20 '16 at 02:20
  • When I search, there is no package-archives file or directory in my emacs directory. – user8128167 Feb 20 '16 at 02:21
  • No, it should work just fine as a normal user. And `package-archives` is a variable, not a file. Try `C-h v package-archives RET`. It should have an entry for the "gnu" archive at `http://elpa.gnu.org/packages/`. – Stefan Feb 20 '16 at 02:28
  • 1
    Actually, there's a more serious problem: I assumed your Emacs is 24.3, but Emacs-24.3 already comes with cl-lib builtin, so I think your Emacs is older (probably <24) which is why it doesn't come with `package-install`. In that case you'll have to install GNU ELPA's cl-lib (which is 100% completely different from the cl-lib.el file in Emacs-24.3) and you'll probably have to do it by hand (or else, you'll first have to install package.el from somewhere. All in all, you'd be better off upgrading your Emacs. – Stefan Feb 20 '16 at 02:31
  • OK, that was it. Silly me! I was using emacs 24.3 at work, but didn't double-check what the emacs version was at home--it turned out to be 24.0. Update your answer with your above comment and I'll mark it as the answer. – user8128167 Feb 20 '16 at 03:04