I've added this to my Emacs init file:
(setq-default auto-fill-function 'do-auto-fill)
(set-default 'fill-column 79)
However a new line begins automatically for all files. I would like this functionality only for files ending in .py.
Related
I'm having difficulty following the instructions for installing speedbar on Emacs.
step 1. Put Lisp:sr-speedbar.el in your load-path, add
(require 'sr-speedbar)
ok put "sr-speedbar.el" in my load-path. (first of all I am making the assumption my load-path is my .emacs.d directory in my root directory.
I go to this link: http://www.emacswiki.org/emacs/sr-speedbar.el
hit the download button, which I end up having to copy/paste the entire file, save it as sr-speedbar.el inside my .emacs.d directory.
~/.emacs.d now has sr-speedbar.el and my .emacs file has the below code:
1 (add-to-list 'load-path "~/.emacs.d/evil")..
2 (require 'evil)..
3 (evil-mode 1)
4 (require 'sr-speedbar)
~
~
so i close out emacs, open it back up and get this error:
Warning (initialization): An error occurred while loading `/Users/johncurry/.emacs':
File error: Cannot open load file, sr-speedbar
To ensure normal operation, 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.
so I $ emacs --debug-init
Debugger entered--Lisp error: (file-error "Cannot open load file" "sr-speedbar"$
require(sr-speedbar)
eval-buffer(#<buffer *load*> nil "/Users/johncurry/.emacs" nil t) ; Reading$
load-with-code-conversion("/Users/johncurry/.emacs" "/Users/johncurry/.emacs"$
load("~/.emacs" t t)
#[0 "^H\205\262^# \306=\203^Q^#\307^H\310Q\202;^# \311=\204^^^#\307^H\312$
command-line()
normal-top-level()
sr-speedbar-open returns no match inside emacs. Any idea how to get this wrong? I'm sure it's just me not understanding the instructions, but I need help with this.
I had the same problem. When I checked the load path of emacs I found that the ~/.emacs.d directory wasn't part of the path.
You can check you load-path use the following command
C-h v load-path RET
To add the path I added the following to my .emacs file.
;; Add the ~/.emacs.d/lisp directory and all subdirectories to the load path of emacs
(let ((default-directory "~/.emacs.d/lisp/"))
(normal-top-level-add-subdirs-to-load-path))
I already had some files in the .emacs.d directory so I add a lisp directory so I wouldn't break anything.
I then reloaded my .emacs file and everything worked.
To reload your .emacs file use the following command
M-x load-file RET .emacs RET
source: https://www.emacswiki.org/emacs/LoadPath
I an new to emacs...so i was trying to install ya-snippets
for this first i downloaded the ya-snippet tar file and then uzipped it and then kept it .emacs.d/packages/
and then added the following code to my .emacs file
;; yasnippet
(add-to-list 'load-path
"~/.emacs.d/packages/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
but my obtaining the following error ...
Warning (initialization): An error occurred while loading `/home/nitesh/.emacs':
Symbol's function definition is void: yas-global-mode
To ensure normal operation, 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.
please tell me the error and as i am new to emacs and please tell what each line is doing my .emacs file written to configure yasnippet ?
and please tell me what to add to .emacs file for ya -snippet to use all c/c++ snippets that comes default with it?
Step One: Place the following two lines near the top of your .emacs file and restart Emacs:
(require 'package)
(package-initialize)
Step Two: M-x list-packages
Step Three: Select Yasnippet with the left mouse click and then click Install, and click Yes.
Step Four: Open up your .emacs file and place this underneath package-initialize
(require 'yasnippet)
(yas-global-mode 1)
Step Five: Restart Emacs and have fun coding. The mode-line will display yas when that minor mode is active.
I'm trying to get semantic completions working with emacs 24 and the version of cedet that comes with it. Completions work for classes I defined in my own source file, but completion isn't working for the standard library or STL stuff Here is my emacs config:
(require 'cedet)
(require 'semantic)
(require 'semantic/ia)
(require 'semantic/bovine/gcc)
(semantic-add-system-include "/usr/include/c++/4.6.3" 'c++-mode)
(setq semantic-default-submodes
'(global-semantic-idle-scheduler-mode
global-semanticdb-minor-mode
global-semantic-idle-summary-mode
global-semantic-idle-completions-mode
global-semantic-highlight-func-mode
global-semantic-decoration-mode
global-semantic-mru-bookmark-mode))
(setq semanticdb-default-save-directory "~/.semanticdb/"
semantic-complete-inline-analyzer-idle-displayor-class 'semantic-displayor-ghost)
(semantic-mode t)
In my ~/.semanticdb directory I only see "!usr!include!c++!4.6!x86_64-linux-gnu!bits!semantic.cache", which isn't even using the version I specified in the config.
When I try M-x semantic-analyze-possible-completions on a std::list, for example, I get an error saying: "Cannot find types for std::list"
Any suggestions for how to debug this or how to fix it?
I was installing today a fresh Ubuntu 13.04 on my new SSD,
and here are my steps to configure CEDET ( I checked that it gives completions for std::list).
Basic setup
Get a fresh emacs and build it from source.
It's as easy as
./configure && make && sudo make install
Add to .emacs
(semantic-mode 1)
That's the whole setup.
Testing
Run emacs without loading anything:
emacs -q test.cc
Enter the code
#include <list>
int main() {
std::list lst;
lst.$
return 0;
}
M-x semantic-mode
with point at $, M-x semantic-ia-show-variants
Troubleshooting
If stuff doesn't work, it's likely that the semanticdb is corrupt.
Just find where it is, for me it's semanticdb-default-save-directory="~/.emacs.d/semanticdb",
and remove everything from there.
Then, when visiting a source file, call semantic-force-refresh.
I find .emacs, and ~/.emacs.d/init.el.
What those files/directories are for?
What's the startup sequence of emacs? Is there any way that makes emacs not to read ~/.emacs.d?
emacs -q or emacs --no-init-file will cause emacs not to read the ~/.emacs file. It should not try to read the ~/.emacs.d if there is a ~/.emacs file. If there isn't a ~/.emacs file it will read ~/.emacs.d/init.el. See the emacs wiki for more info.
See the elisp manual for info on startup.
Emacs' start-up procedure is explained in detail here. The emacs lisp manual ships with emacs, so you should consult that instead of the linked manual on the web, because the former will exactly match your emacs version. To visit it, in emacs type C-h i m elisp RET m Starting Up RET.
Based on sanityinc's answer, I did some experiments by adding (message "* MESSAGE *") at the end of ~/.emacs.d/init.el, my personal el file (smcho.el), and .emacs.el, and I opened Messages buffer.
This is the result from Aquamacs.
Loading prestart plugin files ...
... done.
Shell: /bin/bash
Loading `emulate-mac-keyboard-mode': old-style backquotes detected!
Loading /Users/smcho/Library/Preferences/Aquamacs Emacs/Recent Files.el (source)...done
Cleaning up the recentf list...done (0 removed)
27 environment variables imported from login shell (/bin/bash).
Loading /Applications/Aquamacs.app/Contents/Resources/lisp/aquamacs/edit-modes/auctex.el (source)...done
Loading /Applications/Aquamacs.app/Contents/Resources/lisp/aquamacs/edit-modes/haskell-mode/haskell-site-file.el (source)...done
Loading plugins ...
Loading /Library/Application Support/Aquamacs Emacs/SLIME/site-start.el (source)...done
Loading /Applications/Aquamacs.app/Contents/Resources/lisp/aquamacs/site-start.el (source)...done
... done.
***** Hello from .emacs, and I'm with Aquamacs
***** hello from smcho.el
Loading /Users/smcho/Library/Preferences/Aquamacs Emacs/customizations.el (source)...done
Loading /Users/smcho/Library/Preferences/Aquamacs Emacs/Preferences.el (source)...done
Mark set
one-buffer-one-frame-mode disabled.
Loading /Users/smcho/Library/Preferences/Aquamacs Emacs/frame-positions.el (source)...done
It reads from .emacs and smcho.el, but not from ~/.emacs.d/init.el.
This is from Aqua emacs.
Loading /Users/smcho/.emacs.d/package.el (source)...done
***** Hello from .emacs, and I'm with Aqua emacs
***** hello from smcho.el
For information about GNU Emacs and the GNU system, type C-h C-a.
Again it doesn't read from ~/.emacs.d/init.el, but the starting point if ~/.emacs.d/package.el.
if there is a .emacs file ,then emacs won`t load the ~/.emacs.d/init.el file,if you want to use .emacs.d/init.el file ,you should remove ~/.emacs file
I have a makefile in the project root directory. If I am editing a file in a subdirectory, how do I invoke make from EMACS? M-x compile make will not work as it looks for the makefile in the current directory. But I have the makefile in the project root directory.
Any thoughts?
Edit
As suggested, make -f fullpath_to_makefile did the trick. But I have some includes in the makefile like include "tests/module.mk" which failed. It is looking for "tests" directory in the subdirectory. This can be solved by specifying fully qualified path in the makefile. But I don't think that is a good solution. Any better approaches?
The M-x compile function looks up the compile-command-variable which you can override on the promt -- so just replace it with something like
(cd ../.. && make && cd -)
and let that run.
I also often use a file header (in line 1) such as
// -*- compile-command: "g++ -o myprog myprog.ccc -lfoo -lbar && ./myprog"; -*-
which you can generalize at will with different options. After reloading the file, M-x compile will execute your custom compile command which I find quite useful.
(I use scons, but the principle is the same. Change SConstruct to Makefile and scons to make...)
I've customized by .emacs so that it always compiles the project containing the current buffer's file, however deeply nested; it searches upwards for the first SConstruct and uses that as it's project root directory.
Here's a couple of functions which search up the directory hierarchy looking for SConstruct.
;; inspired by jds-find-tags-file in http://www.emacswiki.org/emacs/EmacsTags
(defun find-sconstruct ()
"recursively searches upwards from buffer's current dir for file named SConstruct and returns that dir. Or nil if not found or if buffer is not visiting a file"
(labels
((find-sconstruct-r (path)
(let* ((parent (file-name-directory path))
(possible-file (concat parent "SConstruct")))
(cond
((file-exists-p possible-file)
(throw 'found-it possible-file))
((string= "/SConstruct" possible-file)
(error "No SConstruct found"))
(t (find-sconstruct-r (directory-file-name parent)))))))
(if (buffer-file-name)
(catch 'found-it
(find-sconstruct-r (buffer-file-name)))
(error "Buffer is not visiting a file"))))
(defun project-root ()
(file-name-directory (find-sconstruct)))
You can then change your compile-command to use project-root e.g.
(concat "cd " (project-root) " && scons")
I use EDE (from CEDET) to define projects, and store compilation commands in the project definition. Look to my config for examples: lines 105-133 -- examples of projects, lines 135-165 -- code, that defines compilation functions, and lines 168-189 -- functions for different kinds of projects -- standard (compile from root directory), and cmake (compilation in separate directory)
Another alternative is to set the variable compilation-process-setup-function which is documented as:
Function to call to customize the compilation process. This function
is called immediately before the compilation process is started. It
can be used to set any variables or functions that are used while
processing the output of the compilation process. The function is
called with variables compilation-buffer' andcompilation-window'
bound to the compilation buffer and window, respectively.
I use Maven alot and wrote this library to support your issue for a Maven context. In the following, change the value of the variable compile-search-file as appropriate:
;;; Support for Maven 2
(require 'compile)
(setq compile-search-file "pom.xml")
(defun find-search-file ()
;; Search for the pom file traversing up the directory tree.
(setq dir (expand-file-name default-directory))
(let ((parent (file-name-directory (directory-file-name dir))))
(while (and (not (file-readable-p (concat dir compile-search-file)))
(not (string= parent dir)))
(setq dir parent
parent (file-name-directory (directory-file-name dir))))
(if (string= dir parent)
(error "Search file %s is missing" compile-search-file)
(with-current-buffer compilation-last-buffer
(message "Test %s %s." compilation-buffer compilation-window)
(setq default-directory dir)))))
;; Add the following to support Emacs' compile mode:
(add-to-list
'compilation-error-regexp-alist-alist
'(mvn "^\\(.*\\):\\[\\([0-9]*\\),\\([0-9]*\\)\\]" 1 2 3))
(add-to-list 'compilation-error-regexp-alist 'mvn)
(setq compilation-process-setup-function 'find-search-file)
(provide 'maven-support)
When I use Emacs to compile the minibuffer looks something like this;
make -k
and I just add any text I like, such as -f ../../root/Makefile. This might work for you.
Mark
I'm not much of an emacs user, but could you pass make -C ../ or however many directories up you need to go?
After a while of different attempts to make EDE work the way I wanted, I went for .dir-locals.el:
((c++-mode . ((compile-command . "make -C ../build -j2 whatever"))))
I found it slightly better for me than having a // -*- -*- in a header of every file,
and a whole lot better than specifying in my init.el (or any other config) those ede-cpp-root-project with full paths to projects, which I either create too often or move all of a sudden :)
Nice addition to the scheme was cmake which makes compile errors to be 'properly jumpable' since it uses full paths in generated makefiles.
I've just started working on a more generic, extensible, and robust yet still reasonably quick-and-dirty solution I just created. It's somewhat based on the Maven example above but I prefer not mucking around with global variables so I use the let or let* special forms a lot more. And of course it uses make.
Right now it only supports Makefiles but you can add a clause to the (cond) special form in the `my-compilation-process-setup-function' function if you want to support one or more additional different build systems.
It even has doc strings!
You'll see it at my Github eventually.
This should do it:
make -f path_to_rootdir/Makefile -I path_to_rootdir/tests
The -f tells it what makefile to use, the -I tells it where to look for files to be included in the makefile (that aren't in the local directory).
Start with M-x compile RET. When it prompts for a command, just enter cd /path/to/root && make and hit return. This command works for all variants of make and handles the "included makefile" problem without any extra flags.
The next time you type M-x compile RET, this new string will be presented as the default, so you only have to hit return. On the off chance that you're actively compiling multiple projects within emacs, you can use M-p and M-n to move backwards and forwards through the history of compile comamnds.