Emacs Init File Line Numbering - emacs

I am trying to display line numbers in emacs on the left hand side. I know it is the linum-mode. When I do M-x linum-mode, my emacs can't find linum-mode. It only finds line-numbers-mode which displays it on the mode bar at the bottom. Why does it not have linum-mode?
Also, when I put (menu-bar-mode t) or even (menu-bar-mode 1), the menu bar does not start at start-up.
When I put (global-linum-mode t) I get the following init error (using --debug-init):
Debugger entered--Lisp error: (void-function global-linum-mode)
(global-linum-mode t)
eval-buffer(#<buffer *load*> nil "/Users/nayef/.emacs.d/init.el" nil t) ; Reading at buffer position 68
load-with-code-conversion("/Users/nayef/.emacs.d/init.el" "/Users/nayef/.emacs.d/init.el" t t)
load("/Users/nayef/.emacs.d/init" t t)
This is extremely extremely frustrating. It works on one computer over SSH but when I do it on my laptop it does not work. I am starting to understand that even though Emacs is more powerful than VIM, VIM is at least 10 times easier to use, less keystrokes and requires WAY less modifications.

Which version of Emacs do you have? linum-mode is included with Emacs 23 and Emacs 24. If you can, you should probably upgrade to those version. If you can't upgrade and you have Emacs 22, you'll need to do the following steps:
Download linum.el on your system (let's say it's in /home/nayefc/).
Add the line (add-to-list 'load-path "/home/nayefc/") to your .emacs
Add the line (require 'linum) to your .emacs
Restart Emacs, and you should be able to call M-x linum-mode. Good luck.
Vincent.

You're having problems because linum-mode is not a standard part of any Emacs distribution; it has to be installed. You can get it here.

Related

Launch make and go to the error position by shortcuts within Emacs

I use Emacs to code. At the moment, to compile an OCaml project, I need to type make in a terminal. If there is an error, I have to go back to Emacs to find the erroneous file and location by following the error indication.
Now, I would like to launch make inside Emacs by a keyboard shortcut, which opens a buffer to show the compilation, then
1) if there is no error, then close the buffer automatically
2) if there is an error, another shortcut will lead me to the erroneous file and line within Emacs.
Does anyone know how to write .emacs to enable this mechanism?
PS: This is my current .emacs.
I have posted a question to compile one .tex file within Emacs by a shortcut (Ctrl + c + m + m), this works well. But in case of error, I don't ask it to lead me to the error position.
M-x compile RET
See the Emacs manual, node Compilation.
And see node Compilation Mode for how to visit error occurrences.
Some years back, I had the same question, here's the answer I got on the #emacs irc channel.
;; from enberg on #emacs
(setq compilation-finish-function
(lambda (buf str)
(if (null (string-match ".*exited abnormally.*" str))
;;no errors, make the compilation window go away in a few seconds
(progn
(run-at-time
"2 sec" nil 'delete-windows-on
(get-buffer-create "*compilation*"))
(message "No Compilation Errors!")))))
;; save the file when I press compile
(setq mode-compile-always-save-buffer-p t)

Customizing emacs in .emacs file

I want emacs to start with specific settings by default. I found that I need to edit the .emacs file in my home directory and use LISP language. However I do get some errors. I need to have:
Windows split by vertical line (I work in C++ with headers and source files)
Column number mode
Cua-mode enabled (to work with normal copy, cut & paste shortcuts)
That's what I have in my .emacs file:
(column-number-mode)
(load "cua-mode")
(CUA-mode t)
(split-window-right)
I'ver tried coding two middle settings in one - (cua-mode). It didn't work out well.
The column-number-mode works, cua does not load and my window is split horizontally (top and bottom window). Where is my error? Thanks for feedback.
From the comments to the question:
if you're using Emacs 24.1 or later,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-right)
but if you're using an earlier version,
(column-number-mode)
(load "cua-mode")
(cua-mode t)
(split-window-horizontally)
By the way, the split-window-horizontally also works in later versions of Emacs (I'm using Emacs 25.2.1).

Emacs version 24.4: New obnoxious loss of indentation on hitting RETURN

Starting with Emacs 24.4, when I type a line beginning with white space (a typical way to
denote a new paragraph) and at the end of it I hit RETURN, the white space disappears.
This problem appears also with 'emacs -Q'.
My .emacs file uses a rather plain text-mode paragraphing scheme, namely,
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'paragraph-indent-minor-mode)
which has been working without problems for a dozen years. The bug appeared when I installed the current (24.4) version.
Basically, I type:
This is a line beginning with four spaces
and as soon as I type RETURN my line immediately becomes
This is a line beginning with four spaces
That is, the indentation vanishes. I'd much appreciate some advice.
Should I post a bug?
In Emacs 24.4, electric-indent-mode is enabled by default. It seems like that's what's causing this problem in combination with paragraph-indent-minor-mode. You can avoid that by turning off Electric Indent mode everywhere (M-x electric-indent-mode) or just in the local buffer (M-x electric-indent-local-mode).
The following will try to keep electric-indent-mode from stepping on the toes of paragraph-indent-minor-mode. It doesn't attempt to be robust in all situations, but I suspect it's entirely sufficient in your situation.
(defvar-local my-local-electric-indent-status :unknown)
(defun my-local-electric-indent-disable ()
"Make `electric-indent-mode' ineffective in the current buffer."
(setq my-local-electric-indent-status electric-indent-mode)
(electric-indent-local-mode -1))
(defun my-local-electric-indent-restore ()
"Restore original status of `electric-indent-mode' in the current buffer."
(unless (eq my-local-electric-indent-status :unknown)
(electric-indent-local-mode my-local-electric-indent-status)))
(add-hook 'paragraph-indent-minor-mode-on-hook #'my-local-electric-indent-disable)
(add-hook 'paragraph-indent-minor-mode-off-hook #'my-local-electric-indent-restore)
If you're not running at least Emacs 24.3, replace the defvar-local with:
(defvar my-local-electric-indent-status :unknown)
(make-variable-buffer-local 'my-local-electric-indent-status)
;;(global-set-key "\em" 'newline) ;;for emacs 23
global-set-key "\em" 'electric-newline-and-maybe-indent) ;;for emacs 24

How to configure emacs to work with ipython

I'm using ubuntu 14.04, emacs 24.3.1, python 2.7.6, ipython 1.2.1, python-mode 6.1.3. Ipython has been working well within emacs for at least a year, however, I have the following problem since two weeks ago.
use C-c! to start default interpreter, ipython shows as I hoped, but instead of split frame and show in another window, it appears in the original code window. (this is a minor problem)
use C-c| to execute a region, python interpreter starts, and the code sends to the python interpreter instead of ipython interpreter
I searched on SO, but this problem seems too recent to have an answer. I googled, found this page https://answers.launchpad.net/python-mode/+question/250905, tried methods therein, still didn't work... Could anyone help me fix the problem? Many thanks!
My .emacs python part looks like
(require 'python-mode)
(setq-default py-shell-name "ipython")
(setq-default py-which-bufname "IPython")
; switch to the interpreter after executing code
(setq py-shell-switch-buffers-on-execute-p t)
(setq py-switch-buffers-on-execute-p t)
; don't split windows
(setq py-split-windows-on-execute-p nil)
In order to split the window
(setq py-split-windows-on-execute-p t)
is needed, resp. reset to default - last line in example. Maybe check settings via M-x customize ... also, which may conflict with setq from init.
When selecting shell for execution: a shebang in buffer might override default py-shell-name.
When shebang should be ignored, use
(setq py-force-py-shell-name-p t)
See menu
Python/Customize/Switches/Interpreter
for an easy way to change this value during current session.

Emacs: How do I stop "*Buffer List*" from showing when opening 3+ files

When I open 3+ files in emacs, I get a split window with one of my files in the upper buffer and Buffer List in the lower buffer.
How can I get emacs to NOT put Buffer List there, but instead show another one of my files.
thanks. -John
Try this:
(setq inhibit-startup-buffer-menu t)
Documentation can be found here.
Note: This option was introduced in Emacs 22.
For Emacs 21 and before, you could add the following workaround to your .emacs which will force Emacs to only have one window visible upon startup:
(add-hook 'after-init-hook 'delayed-delete-other-windows)
(defun delayed-delete-other-windows ()
"need the call to happen after startup runs, so wait for idle"
(run-with-idle-timer 0 nil 'delete-other-windows))