Symbol's value as variable is void: ac-source-tern-completion [duplicate] - emacs

This is my ~/.emacs file:
(setq-default c-basic-offset 4 c-default-style "linux")
(setq-default tab-width 4 indent-tabs-mode t)
(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
I'm getting a warning when I open up emacs:
Warning (initialization): An error occurred while loading
c:/home/.emacs:
Symbol's value as variable is void: c-mode-base-map
To ensure normal operations, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with the
--debug-init option to view a complete error backtrace.
I ran --debug-init and this is what it returned. I don't know what I means:
Debugger entered--Lisp error: (void-variable c-mode-base-map)
(define-key c-mode-base-map (kbd "RET") (quote newline-and-indent))
eval-buffer(#<buffer *load*> nil "c:/home/.emacs" nil t)
; Reading at buffer position 311
load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t)
load("~/.emacs" t t)

What this means is that, at the point at which you invoke define-key, c-mode-base-map is not yet defined by anything.
The usual fix is to find out where this is defined and require that module. In this case:
(require 'cc-mode)
However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using eval-after-load. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.

Related

How to remap keys in ido-find-file?

I have been trying to make a few changes to ido-mode to make it more useful. One of the things which I have been trying to do is to remap some of the keys which I use in ido-find-file. The main one is that I want to use C-d to call the ido-enter-dired function instead of having to press C-f+C-d which does the same thing.
This is my ido setup so far:
(defun ali/ido ()
"My configuration for ido-mode"
(require 'ido)
(setq ido-create-new-buffer 'always)
;; Making sure that ido works in M-x
(global-set-key
"\M-x"
(lambda ()
(interactive)
(call-interactively
(intern
(ido-completing-read
"M-x "
(all-completions "" obarray 'commandp))))))
;; Ido keybindings
(defun ido-keybindings ()
(define-key ido-completion-map (kbd "C-d") 'ido-enter-dired))
(add-hook 'ido-setup-hook 'ido-keybindings)
(ido-everywhere t)
(ido-mode 1))
However whenever, I try to use C-d in ido-find-file I always get this error:
Debugger entered--Lisp error: (error "Command attempted to use minibuffer while in minibuffer")
When called with the minibuffer active, your command uses a recursive minibuffer to read input using ido-completing-read.
Use this as your command instead:
(lambda ()
(interactive)
(let ((enable-recursive-minibuffers t)) ; <=====================
(call-interactively
(intern
(ido-completing-read
"M-x "
(all-completions "" obarray 'commandp))))))
C-h v enable-recursive-minibuffers tells us:
enable-recursive-minibuffers is a variable defined in C source code.
Its value is nil
Documentation:
Non-nil means to allow minibuffer commands while in the minibuffer.
This variable makes a difference whenever the minibuffer window is active.
Also see minibuffer-depth-indicate-mode, which may be handy if this
variable is non-nil.
You can customize this variable.

Emacs: Symbol's value as variable is void

This is my ~/.emacs file:
(setq-default c-basic-offset 4 c-default-style "linux")
(setq-default tab-width 4 indent-tabs-mode t)
(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
I'm getting a warning when I open up emacs:
Warning (initialization): An error occurred while loading
c:/home/.emacs:
Symbol's value as variable is void: c-mode-base-map
To ensure normal operations, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with the
--debug-init option to view a complete error backtrace.
I ran --debug-init and this is what it returned. I don't know what I means:
Debugger entered--Lisp error: (void-variable c-mode-base-map)
(define-key c-mode-base-map (kbd "RET") (quote newline-and-indent))
eval-buffer(#<buffer *load*> nil "c:/home/.emacs" nil t)
; Reading at buffer position 311
load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t)
load("~/.emacs" t t)
What this means is that, at the point at which you invoke define-key, c-mode-base-map is not yet defined by anything.
The usual fix is to find out where this is defined and require that module. In this case:
(require 'cc-mode)
However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using eval-after-load. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.

Emacs Prelude - Electric indentation

I am trying to get electric indentation working in prelude.
In the .emacs.d/personal/personal.el file I have added the below
;;; package --- Summary
;;; adding indent for python and binding for python-django
;;; Code:
(electric-indent-mode +1)
;;; Commentary:
;;; package --- Summary
;;; adding indent for python and binding for python-django
;;; Code:
(global-set-key (kbd "C-x j") 'python-django-open-project)
;;; Commentary:
(provide 'personal)\n
;;; personal.el ends here
electric should work as I got it from bbatsov's site.electric-indent
I notic however that even ctrl-j isn't working to indent. how do I fix this?
EDIT error from personal.el
Debugger entered--Lisp error: (void-variable n)
eval-buffer(#<buffer *load*-827116> nil "/home/sayth/.emacs.d/personal/personal.el" nil t) ; Reading at buffer position 327
load-with-code-conversion("/home/sayth/.emacs.d/personal/personal.el" "/home/sayth/.emacs.d/personal/personal.el" nil nil)
load("/home/sayth/.emacs.d/personal/personal.el")
mapc(load ("/home/sayth/.emacs.d/personal/personal.el"))
(progn (message "Loading personal configuration files in %s..." prelude-personal-dir) (mapc (quote load) (directory-files prelude-personal-dir (quote t) "^[^#].*el$")))
(if (file-exists-p prelude-personal-dir) (progn (message "Loading personal configuration files in %s..." prelude-personal-dir) (mapc (quote load) (directory-files prelude-personal-dir (quote t) "^[^#].*el$"))))
eval-buffer(#<buffer *load*> nil "/home/sayth/.emacs.d/init.el" nil t) ; Reading at buffer position 4738
load-with-code-conversion("/home/sayth/.emacs.d/init.el" "/home/sayth/.emacs.d/init.el" t t)
load("/home/sayth/.emacs.d/init" t t) #[0 "\205\262
electric-indent-mode seems to work just fine when I test in Emacs 24.3.50. You should keep in mind that it remaps C-j to electric-indent-just-newline. It simply inserts a newline, without any auto-indentation.
This makes a lot of sense, as the RET auto-indents when the mode is enabled. I seem to recall it was buggy in older versions of Emacs, so I'd suggest taking a look at emacs-snapshot if you want to use it.

elisp difference between emacs 23 and 24, or something else

my previous fine key binding for cscope on emacs 23:
(define-key global-map [(control ,)] 'cscope-pop-mark)
now got an error on emacs 24
Debugger entered--Lisp error: (invalid-read-syntax ")")
eval-buffer(#<buffer *load*<3>> nil "/home/ted/.emacs.d/ted.el" nil t) ; Reading at buffer position 12743
I try to evaluate in in *scratch*, then the following error, but emacs 23 returned ok:
Debugger entered--Lisp error: (invalid-read-syntax ")")
read(#<buffer *scratch*>)
preceding-sexp()
eval-last-sexp-1(t)
eval-last-sexp(t)
eval-print-last-sexp()
call-interactively(eval-print-last-sexp nil nil)
So let's fill in the relevant part of the comment pointed at by tripleee:
Another cause of trouble is vector notation
for key sequence notation: instead of [(control ,)] and [(control ')],
you should write [(control ?,)] and [(control ?')], which will work in
older Emacsen too.
It's [(control ,)] that is invalid syntax in Emacs 24. Spell it as [(control \,)] and the error will disappear with no change to the meaning and no loss of compatibility with older Emacsen.

Whats wrong with the following unbind script?

(dolist (abcc '("C-a" "C-b"))
(global-unset-key (kbd abcc)))
It keeps on giving the error :
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p abcc)
read-kbd-macro(abcc)
#[(keys) "\301!\207" [keys read-kbd-macro] 2 2180088](abcc)
(kbd abcc)
(global-unset-key (kbd abcc))
(while --dolist-tail-- (setq abcc (car --dolist-tail--)) (global-unset-key (kbd abcc)) (setq --dolist-tail-- (cdr --dolist-tail--)))
(let ((--dolist-tail-- ...) abcc) (while --dolist-tail-- (setq abcc ...) (global-unset-key ...) (setq --dolist-tail-- ...)))
(dolist (abcc (quote ...)) (global-unset-key (kbd abcc)))
eval-buffer(#<buffer *load*> nil "/home/name/.emacs" nil t) ; Reading at buffer position 63
load-with-code-conversion("/home/name/.emacs" "/home/name/.emacs" t t)
load("~/.emacs" t t)
#[nil "\205\264
I initially thought that this is a bug in Emacs. I was very surprised nobody's come across this before.
Here is a workaround you can use:
(dolist (abcc '("C-a" "C-b"))
(global-unset-key (read-kbd-macro abcc)))
What happens is kbd is a macro that wraps a function, however it doesn't evaluate its parameter explicitly. So the symbol abcc is getting passed straight to the function.
After a bit more thinking (and reading the docs). It's actually user error.
The doc-string for kbd clearly states that it should be used on string constants.
So kbd should be used when you only want a key's internal representation to appear in the compiled byte-code. e.g.
(define-key foo-mode-map (kbd "C-a") 'foo)
But read-kbd-macro should be used when you want the argument to be evaluated.
(keys) is a macro that just passes right through to (read-kbd-macro). The former also errors out for me for some reason, but the latter doesn't. Try that instead?
kbd is a macro, so it does not evaluate its arg.