I've recently started using Emacs and an issue I've been facing is that the editor automatically converts all the tabs to spaces. It has started to get a bit annoying now.
Here's my .emacs file for reference:
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(when no-ssl
(warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
(add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)
(custom-set-variables
'(custom-enabled-themes (quote (dracula)))
'(custom-safe-themes)
'(display-line-numbers-type (quote relative))
'(global-display-line-numbers-mode t)
'(menu-bar-mode nil)
'(package-selected-packages
(quote
(company-irony-c-headers company-irony micgoline elpy company-jedi molokai-theme gruvbox-theme autopair auto-complete anaconda-mode nyan-mode dracula-theme company)))
'(scroll-bar-mode nil)
'(tool-bar-mode nil))
(custom-set-faces
)
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq inhibit-startup-message t) ;; hide the startup message
(elpy-enable)
(pyenv-mode)
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "-i --simple-prompt")
(require 'powerline)
Any suggestions on how to stop emacs from doing this behaviour?
As suggested by Drew, I am posting this as answer:
Did you check variable indent-tabs-mode?
With this you should be able to switch between emacs using spaces or tabs.
As described in the emacs wiki here I would assume, some active mode is setting this to nil in your emacs.
You can find another explanation with links to discussions about if tabs are evil or not here
EDIT:
It seems that strangely the python-mode sets indent-tabs-mode to t.
Maybe this Emacs Wiki entry solves your problem. This snippet from the wiki:
(add-hook 'python-mode-hook
(lambda ()
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
(setq-default py-indent-tabs-mode t)
(add-to-list 'write-file-functions 'delete-trailing-whitespace)))
looks like it will do the trick.
Hope this helps.
Related
I've recently made a few changes in my init emacs file, and I've noticed with --debug-init that some load files seem to be missing. Here is the output from the debugger
Debugger entered--Lisp error: (file-error "Cannot open load file" "/home/andre/a-m")
load("/home/andre/a-m" nil nil t)
load-file("a-m")
eval-buffer(#<buffer *load*> nil "/usr/local/share/emacs/site-lisp/default.el" nil t) ; Reading at buffer position 269
load-with-code-conversion("/usr/local/share/emacs/site-lisp/default.el" "/usr/local/share/emacs/site-lisp/default.el" t t)
load("default" t t)
#[0 "\205\262
command-line()
normal-top-level()
I've searched for what the a-m file stands for online, and how to correct these errors but without success. Thanks for any help!
Best
Andre
Edit: Here is the init file. I've just changed some info on jabber (email) but other than that the file is unchanged
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; File name: ` ~/.emacs '
;; ---------------------
;; If you need your own personal ~/.emacs
;; please make a copy of this file
;; an placein your changes and/or extension.
;; Copyright (c) 1997-2002 SuSE Gmbh Nuernberg, Germany.
;; Author: Werner Fink, <feedback#suse.de> 1997,98,99,2002
;; Test of Emacs derivates
;; -----------------------
(load-library "url-handlers")
;; Always use PDFLaTeX
(setq TeX-PDF-mode t)
;; TeXcount setup for AUCTeX
(require 'tex)
(add-to-list 'TeX-command-list
(list "TeXcount" "texcount %s.tex" 'TeX-run-command nil t))
(load "auctex.el" nil t t)`
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
;; MELPA
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
(package-initialize))
;; YASNIPPETS
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets" ;; personal snippets
"~/.emacs.d/plugins/yasnippet/snippets/" ;; the default collection
))
(yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already.
;; Timestamp controls
(add-hook 'before-save-hook 'time-stamp)
(setq time-stamp-pattern nil)
;; Controls for calendar
(setq european-calendar-style t)
(set-default 'truncate-lines t)
;; Controls for jabber
(require 'jabber)
;;;;;;;;;;;;;;;
;; TRAMP mode
;;;;;;;;;;;;;;;
(setq tramp-default-method "ssh")
;;;;;;;;;;;
;;ORG mode
;;;;;;;;;;;
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-agenda-files (list "~/org/NOTES.org"))
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "firefox")
(setq org-support-shift-select 't)
(setq org-agenda-include-diary t)
(setq org-src-fontify-natively t)
;;;;;;;;;;;
;;G-CODE
;;;;;;;;;;;
(require 'generic-x)
(define-generic-mode gcode-generic-mode
'(("(" . ")"))
(apply 'append
(mapcar #'(lambda (s) (list (upcase s) (downcase s) (capitalize s)))
'("sub" "endsub" "if" "do" "while" "endwhile" "call" "endif"
"sqrt" "return" "mod" "eq" "ne" "gt" "ge" "lt" "le" "and"
"or" "xor" "atan" "abs" "acos" "asin" "cos" "exp"
"fix" "fup" "round" "ln" "sin" "tan" "repeat" "endrepeat")))
'(("\\(#<_?[A-Za-z0-9_]+>\\)" (1 font-lock-type-face))
("\\([NnGgMmFfSsTtOo]\\)" (1 font-lock-function-name-face))
("\\([XxYyZzAaBbCcUuVvWwIiJjKkPpQqRr]\\)" (1 font-lock-string-face))
("\\([\-+]?[0-9]*\\.[0-9]+\\)" (1 font-lock-constant-face))
("\\(#[0-9]+\\)" (1 font-lock-type-face))
("\\([0-9]+\\)" (1 font-lock-constant-face)))
'("\\.gcode\\'")
nil
"Generic mode for g-code files.")
;;;;;;;;;;;
;;OpenSCAD
;;;;;;;;;;;
(add-to-list 'load-path
"/usr/local/share/emacs/site-lisp/")
(autoload 'scad-mode "scad-mode" "Activate OpenSCAD mode." 'interactive)
(add-to-list 'auto-mode-alist '("\\.scad\\'" . scad-mode))
;;;;;;;;
;;ANSYS
;;;;;;;;
(add-to-list 'load-path
"/usr/local/share/emacs/site-lisp/")
(autoload 'ansys-mode "ansys-mode" "Activate Ansys mode." 'interactive)
(add-to-list 'auto-mode-alist '("\\.txt\\'" . ansys-mode))
(add-to-list 'auto-mode-alist '("\\.db\\'" . ansys-mode))
; (add-to-list 'auto-mode-alist '("\\.dat\\'" . ansys-mode))
; (add-to-list 'auto-mode-alist '("\\.inp\\'" . ansys-mode))
;;;;;;;;;;;
;;LS-DYNA
;;;;;;;;;;;
(add-to-list 'load-path
"/usr/local/share/emacs/site-lisp/")
(autoload 'lsdyna-mode "lsdyna" "Enter ls-dyna mode." t)
(setq auto-mode-alist (cons '("\\.k\\'" . lsdyna-mode) auto-mode-alist))
;;;;;;;;;;;
;;ABAQUS
;;;;;;;;;;;
;; ;; setup files ending in “.inp” to open in python-mode
;; (add-to-list 'auto-mode-alist '("\\.inp\\'" . python-mode))
(add-to-list 'load-path
"/usr/local/share/emacs/site-lisp/")
(autoload 'abaqus-mode "abaqus" "Enter abaqus mode." t)
(setq auto-mode-alist (cons '("\\.inp\\'" . abaqus-mode) auto-mode-alist))
;;;;;;;;;;;;;;;;;;;;;;
;; PDF-LATEX+INKSCAPE
;;;;;;;;;;;;;;;;;;;;;;
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(LaTeX-command-style (quote (("" "%(PDF)%(latex) -shell-escape %S%(PDFout)"))))
'(ansys-current-ansys-version "140")
'(jabber-account-list (quote (("myemail.com"))))
'(org-agenda-files (quote ("~/org/NOTES.org")))
'(send-mail-function (quote smtpmail-send-it))
'(smtpmail-smtp-server "smtp.googlemail.com")
'(smtpmail-smtp-service 587))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; ;;;;;;;;;;;
;; ;;GNUPLOT
;; ;;;;;;;;;;;
;; (add-to-list 'Info-default-directory-list "/usr/info")
;; ;; load the file
;; (require 'gnuplot)
;; ;; specify the gnuplot executable (if other than /usr/bin/gnuplot)
;; (setq gnuplot-program "/usr/bin/gnuplot")
;; ;; automatically open files ending with .gp or .gnuplot in gnuplot mode
;; (setq auto-mode-alist
;; (append '(("\\.\\(gp\\|gnuplot\\|p\\)$" . gnuplot-mode)) auto-mode-alist))
; GIT controls
(add-to-list 'load-path ".../git/contrib/emacs")
(require 'git)
(require 'git-blame)
(require 'vc-git)
;; OCTAVE
(autoload 'run-octave "octave-inf" nil t)
(put 'upcase-region 'disabled nil)
;; PHP
(autoload 'php-mode "php-mode" "Major mode for editing php code." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
;; Command for automatic alignment of comments
(defun align-comment (beg end)
(interactive "r")
(align-regexp beg end (concat "\\(\\s-*\\)" comment-start))
)
(global-set-key "\C-c\C-a" 'align-comment )
;; Flyspell mode binding to F6 key
(global-set-key [f6] 'flyspell-mode) ; F6
;; Command for automatic auto-fill
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Thanks for your help. I didn't read the new ansys-mode https://github.com/dieter-wilhelm/ansys-mode documentation properly. Here is the issue:
Please have a look at the accompanying default.el’ customisation example. It can be used as a configuration file (after moving it e. g. to/usr/share/emacs/site-lisp’ or c:\EMACS_INSTALLDIR\site-lisp’, hint: The directory site-lisp/ in the Emacs installation tree is in its default load-path). Yetdefault.el’ is loaded AFTER your personal Emacs configuration file (if there is any) ~/.emacs’ (or~/.emacs.d/init.el’)! If you intend to change the following settings with Emacs’ customisation system or changing them directly in your personal configuration file, you must either set the variable inhibit-default-init’ tot’ “(setq inhibit-default-init t)” in your personal configuration file or remove `default.el’ otherwise your settings might be overwritten!
So I just added (setq inhibit-default-init t) to the init file.
Thanks again!
Note that with Git 2.18 (Q2 2018), the scripts in contrib/emacs/ have outlived their usefulness and have been replaced with a stub that errors out and tells the user there are replacements.
So the init error message might not apply anymore in 2018.
See commit 6d5ed48 (11 Apr 2018) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit 7d7d051, 08 May 2018)
git{,-blame}.el: remove old bitrotting Emacs code
The git-blame.el mode has been superseded by Emacs's own
vc-annotate
(invoked by C-x v g).
Users of the git.el mode are now much better off using either Magit or the Git backend for Emacs's own VC mode.
These modes were added over 10 years ago when Emacs's own Git support
was much less mature, and there weren't other mature modes in the wild
or shipped with Emacs itself.
These days these modes have few if any users, and users of git aren't
well served by us shipping these (some OS's install them alongside git
by default, which is confusing and leads users astray).
[...] rather than receive a cryptic load error when they upgrade,
existing users will get an error directing them to the README file, or
to just stop requiring these modes
See "git/contrib/emacs/README" for more.
My emacs takes a few seconds to start up every time, which is slower than I'd expect. During that time, it says "contacting host: " marmalade-repo and melpa.
Is my current config a reasonable one? Is there a way I can speed it up, while still being able to install packages when I need them?
;; init.el --- Emacs configuration
;; INSTALL PACKAGES
;; --------------------------------------
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar myPackages
'(better-defaults
paredit
idle-highlight-mode
ido-ubiquitous
find-file-in-project
smex
scpaste
ein
elpy
flycheck
material-theme
py-autopep8))
(package-refresh-contents)
(mapc #'(lambda (package)
(unless (package-installed-p package)
(package-install package)))
myPackages)
;; BASIC CUSTOMIZATION
;; --------------------------------------
(setq inhibit-startup-message t) ;; hide the startup message
(load-theme 'material t) ;; load material theme
(global-linum-mode t) ;; enable line numbers globally
;; PYTHON CONFIGURATION
;; --------------------------------------
(elpy-enable)
(elpy-use-ipython)
;; use flycheck not flymake with elpy
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode))
;; enable autopep8 formatting on save
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
;; enable electric pair minor mode
(defun electric-pair ()
"If at end of line, insert character pair without surrounding spaces.
Otherwise, just insert the typed character."
(interactive)
(if (eolp) (let (parens-require-spaces) (insert-pair)) (self-insert-command 1)))
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\"" 'electric-pair)
(define-key python-mode-map "\'" 'electric-pair)
(define-key python-mode-map "(" 'electric-pair)
(define-key python-mode-map "[" 'electric-pair)
(define-key python-mode-map "{" 'electric-pair)))
;; Send line from code buffer
;; http://stackoverflow.com/questions/27777133/change-the-emacs-send-code-to-interpreter-c-c-c-r-command-in-ipython-mode/30774439#30774439
(defun my-python-line ()
(interactive)
(save-excursion
(setq the_script_buffer (format (buffer-name)))
(end-of-line)
(kill-region (point) (progn (back-to-indentation) (point)))
(if (get-buffer "*Python*")
(message "")
(run-python "ipython" nil nil))
;; (setq the_py_buffer (format "*Python[%s]*" (buffer-file-name)))
(setq the_py_buffer "*Python*")
(switch-to-buffer-other-window the_py_buffer)
(goto-char (buffer-end 1))
(yank)
(comint-send-input)
(switch-to-buffer-other-window the_script_buffer)
(yank))
(end-of-line)
(next-line)
)
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\C-cn" 'my-python-line)))
Recently, loading packages from MELPA has been really slow, I'm not so sure why. What you can do to get around this (or at least make sure it only happens once) is to run Emacs in daemon mode, and then connect to it whenever you want to edit a file. It means that the cost of loading is only incurred once. It's as simple as running emacs --daemon at startup. Then you connect via emacsclient.
I am getting these two issues :
In toplevel form:
init.el:28:1:Warning: `(add-path (p) (add-to-list (quote load-path) (concat
emacs-root p)))' is a malformed function
init.el:42:1:Error: Cannot open load file: exec-path-from-shell
during compiling the following elisp:
(eval-when-compile (require 'cl))
;; root of all emacs-related stuff
(eval-when-compile
(defvar emacs-root
(if (or (eq system-type 'cygwin)
(eq system-type 'gnu/linux)
(eq system-type 'linux)
(eq system-type 'darwin))
"~/.emacs.d/" "z:/.emacs.d/")
"Path to where EMACS configuration root is."))
(eval-when-compile
(defvar emacs-root "~/.emacs.d"
"Path to where EMACS configuration root is."))
;; path to where plugins are kept
(defvar plugin-path (concat emacs-root "el-get")
"*Path to el-get plugins.")
;; for portability with < 24.3 EMACS
(unless (fboundp 'cl-labels) (fset 'cl-labels 'labels))
;; add paths to various configuration modes
(cl-labels
((add-path (p)
(add-to-list 'load-path
(concat emacs-root p))))
(add-path ".")
(add-path "settings")
(add-path "site-lisp")
(add-path "erlang")
(add-path "exec-path-from-shell"))
;; set PATH, because we don't load .bashrc
(require 'exec-path-from-shell) ;; <- Error: Cannot open load file: exec-path-from-shell
both these issues are very puzzling to me.
I don't see why this fund considered "malformed"
`(add-path (p) (add-to-list (quote load-path) (concat
emacs-root p)))'
and secondly why "require" is not able to load file.
these issues only happen during compilation, not compiled code works ok
would really appreciate any pointers
Regards, Roman
cl-labels is provided by cl-lib, not by cl. So you need (require 'cl-lib) (which you can also wrap in eval-when-compile).
You need to have "cl-lib" loaded at compile time:
(eval-when-compile (require 'cl-lib))
Also, as Stefan explained in his comments in your other question, you should not define variables in eval-when-compile. Just use defvar.
I'm setting up emacs for Ruby on Rails development, and would like the ECB window to show only the directory for the project I'm working on. Is that possible?
Let's assume that I start emacs after I cd to the project's directory. I've added the following to my .emacs:
(defvar start-dir (getenv "PWD"))
(custom-set-variables
'(ecb-layout-name "left14")
'(ecb-layout-window-sizes (quote (("left14" (0.2564102564102564 . 0.6949152542372882) (0.2564102564102564 . 0.23728813559322035)))))
'(ecb-options-version "2.32")
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1))
'(ecb-source-path (list start-dir))
'(ecb-tip-of-the-day nil)
'(ecb-tree-buffer-style (quote ascii-guides))
'(inhibit-startup-screen t))
Notice I've created a list containing only the start-dir. However ECB shows both the start-dir and the root (/) dir.
I figured out a solution to only show the directory from which I run emacs in the ECB window:
(defvar start-dir (getenv "PWD"))
(defvar start-dir-name (car (last (split-string start-dir "/"))))
(custom-set-variables
'(ecb-layout-name "left14")
'(ecb-layout-window-sizes (quote (("left14" (0.2564102564102564 . 0.6949152542372882) (0.2564102564102564 . 0.23728813559322035)))))
'(ecb-options-version "2.32")
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1))
'(ecb-source-path (list (list start-dir start-dir-name)))
'(ecb-tip-of-the-day nil)
'(ecb-tree-buffer-style (quote ascii-guides))
'(inhibit-startup-screen t))
Try (setq ecb-source-path (quote "/path/to/project/")). Your present setup makes ecb-source-path nil, which you can see if you do describe-variable.
I'm trying to configure my .emacs file to work in a Windows, Linux, and Mac environment--specifically, I need it to choose the correct font and a certain directory for org-mode.
I have tried the following which loads the correct font, but does not load the path specified for org-mode:
;; On Windows
(if (eq system-type 'windows-nt)
(set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
(setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
)
;; On Linux
(if (eq system-type 'gnu/linux)
(set-default-font "Inconsolata-11")
(setq load-path (cons "~/elisp/org-current/lisp" load-path))
)
I have tried the following which on my Windows machine returns the error Font Inconsolata-11 is not defined, and on my Linux machine returns the error Font -outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1 is not defined. For both, the specified org path is not loaded:
;; On Windows
(if (eq system-type 'windows-nt)
(setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
(set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
)
;; On Linux
(if (eq system-type 'gnu/linux)
(setq load-path (cons "~/elisp/org-current/lisp" load-path))
(set-default-font "Inconsolata-11")
)
I evaluated the system-type variable in both environments, and they both evaluate correctly.
Can anyone see what's wrong--also, I'm not very versed in emacs-lisp, can you see what incorrect assumptions I'm making?
Thank you,
Zachary
note that if in lisp is if-then-else. so, in your first case you are doing if windows, set the font, ELSE set the loadpath for windows! then independantly, you are doin if linux setthe font, else set the loadpath for linux!
try
(if (eq system-type 'windows-nt)
(progn
(setq load-path (cons "~/elisp/org-6.34c/lisp" load-path))
(set-default-font "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")
)
(progn
(setq load-path (cons "~/elisp/org-current/lisp" load-path))
(set-default-font "Inconsolata-11")
)
)
this won't work on mac, or whatever, but if you're only ever using NT or linux, this should work. Otherwise you can stick the other if outside the 2nd progn...