Emacs indentation in Asm mode - emacs

I am looking for the equivalent of c-indent-level and ruby-indent-level, for asm-mode. That is, I want to force the indentation to 4 spaces, and I want them to be replaced with blanks.
What I've seen tells me it does not exist for asm-mode. Could someone please tell me this is wrong?
I tried this also: Set 4 Space Indent in Emacs in Text Mode , to no av.
I have tried:
(setq tab-width 4)
(setq indent-line-function 'insert-tab)
(setq asm-indent-level 4)
This works however:
(custom-set-variables
'(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))))
But I wonder if there is a way to define that for asm-mode only. What if I wanted to keep the default tab behaviour for other modes?

asm-mode uses the function tab-to-tab-stop for indentation, that's why tab-stop-list is working. As far I know there is nothing more that you can do. You might consider using some of the "more advanced" asm modes such as - gas-mode or asm86-mode.

Emacs defines hooks for every (?) major mode. If you do H-m in assembly file, you can see at the end of text section that Assembler mode hook is called `asm-mode-hook'. So you can add your code to run when assembler mode is selected for a buffer like this:
(add-hook 'asm-mode-hook (lambda()
(setq tab-width 4)
(setq indent-line-function 'insert-tab)
(setq asm-indent-level 4)))
Note, tab-width and indent-line-function are already buffer local variables, so setting them changes their value only for the current buffer. This is probably what you want. If you setq some other variables, you may want to make them buffer local using (make-variable-buffer-local VARIABLE) function.

Related

Projectile not working anymore. How can I reenable it?

When I start emacs now, prelude is no longer activated. This is my personal.el file:
(setq-default tab-width 4)
(setq tab-width 4)
(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.
'(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))))
(setq exec-path (append exec-path '("/usr/bin/")))
(setq auto-fill-mode -1)
(setq-default fill-column 99999)
(setq fill-column 99999)
(setq global-hl-line-mode -1)
(require 'projectile)
(defun myprojectilehook ()
(projectile-mode)
)
(add-hook 'find-file-hook 'myprojectilehook)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
I tried to add a hook to find-file-hook, that would enable projectile for the current buffer, but without much success. When I open emacs projectile is disabled. When I visit a new file, projectile remains disabled. What am I doing wrong?
There is a projectile-global-mode as well that activates Projectile everywhere there is a project context. projectile-global-mode is activated by default in Prelude, so I guess the real issue has to do with your Prelude setup. At any rate:
(projectile-global-mode +1)
should unconditionally enable projectile for all of your projects. Keep in mind that that projectile will always be disabled for buffers in directories that projectile doesn't consider to be projects (unless you add a .projectile file in them to mark the root folder of a project).
P.S. I am the author of both Prelude and Projectile, so fell free to post additional details about your problems with Prelude & Projectile here or at their respective issue trackers at GitHub.
Note that prior to Emacs 24, (projectile-mode) will toggle the mode (exactly like calling it with M-x projectile-mode). If it was on, that would turn it off.
Assuming it uses the standard mode definition macros, (projectile-mode 1) would enable, and (projectile-mode -1) disable.
C-h f projectile-mode ought to indicate this.

How do I set emacs to use 3 spaces instead of tabs in verilog mode?

I am pretty new to emacs (using version 23.3) and I wanted to set the default tab key to insert 3 spaces instead of a tab character in verilog mode. I did find a number of posts regarding this in stack overflow. Some of them are: -
How To Force spaces instead of tabs regardless of major mode
Why might my Emacs use spaces instead of tabs?
Emacs global configuration of tabs
But they do not seem to work in verilog mode. This is how my .emacs file looks like
(custom-set-variables
'(tab-stop-list ('(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 114 117 120)))
'(verilog-case-indent 3)
'(verilog-indent-level-directive 0)
'(verilog-indent-level 3)
'(verilog-tab-always-indent nil))
(custom-set-faces
)
(add-hook 'after-change-major-mode-hook
'(lambda ()
(setq-default indent-tabs-mode nil)
(setq tab-width 3)))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 3)
(setq-default standard-indent 3)
If I try to edit a text file, the setup works perfectly and inserts 3 spaces instead of a tab. However it still inserts a tab character when I try to edit a verilog file (.v). I can select the entire text and do M-x untabify to get the required result but is there another direct solution?
In the hook you should use setq instead of setq-default, so you need to rewrite your hook to something like:
(defun my-verilog-hook ()
(setq indent-tabs-mode nil)
(setq tab-width 3))
(add-hook 'verilog-mode-hook 'my-verilog-hook)
P.S. it's better to use dedicated functions in hooks, as it's easier to change them, and you can also remove them from hooks

How do I set Emacs tab size to 4 chars wide for .py files?

I've tried using the following:
(setq-default tab-width 4)
(setq-default tab-stop-list (list 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))
But the size of tabs when editing .py files is still 8 chars wide. In other files it has gone down to 4, so I assume the Python major mode is overriding this somehow. I see that I can set python-indent to 4, but this causes spaces to be inserted (which goes against our code style guide).
How do I make the tabs 4 chars in width?
Update:
I've also tried this, but it didn't do anything:
(add-hook 'python-mode-hook
(setq indent-tabs-mode t)
(setq tab-width 4)
)
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode t)
(setq tab-width 4)
(setq python-indent-offset 4)))
The correct form for the hook is this:
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode t)
(setq tab-width 4)))
You need to put the imperative statements inside a function (lambda).
I've had that same issue, but with C++ files. What finally did it for me was the following in my .emacs.
(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.
'(c-basic-offset 4 t)
)
Actually of course I set it from the C++ mode area of the Customize Emacs menu, but this was the result. I'd see if python mode has something similar. py-basic-offset or something? Surf around the mode settings for pyton.
(setq indent-tabs-mode t)
(setq python-indent-offset 4)

Custom Emacs key bindings are not working

The key bindings I've defined in my .emacs file aren't working. Here's the file:
;init modes
(menu-bar-mode 0)
(tool-bar-mode 0)
(cua-mode)
(column-number-mode)
(fset 'perl-mode 'cperl-mode)
(cperl-set-style PerlStyle)
;keymappings
(global-set-key [f12] 'save-buffer)
(global-set-key [S-f12] 'write-file)
(global-set-key [f7] 'ispell)
(global-set-key [up] 'scroll-one-line-up)
(global-set-key [down] 'scroll-one-line-down)
;functions
(defun scroll-one-line-up (&optional arg)
(interactive "p")
(scroll-up (or arg 1)))
(defun scroll-one-line-down (&optional arg)
(interactive "p")
(scroll-down (or arg 1)))
I know Emacs parses the file since everything else seems to work. It's just that the keys are not being bound.
How can I make it work?
You have an error in your .emacs at line:
(cperl-set-style PerlStyle)
It should be written as:
(cperl-set-style 'PerlStyle)
Since it raises an error that stops parsing .emacs at that point, your key bindings won't be evaluated.
To follow up to my previous answer, you would have to change the binding in the local keymap using a hook variable. Here's an example that I use with java-mode:
(defun java-setup ()
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
indent-tabs-mode nil
tab-width 4
fill-column 96
c-comment-start-regexp "\\(#\\|/\\(/\\|[*][*]?\\)\\)"))
(add-hook 'java-mode-hook 'java-setup)
In your case you would use something like:
(defun mysetup ()
(define-key local-map [f12] 'func))
(add-hook 'your-mode-hook 'mysetup)
Also, fwiw, I do the following to define my global keys:
(defun function-key-help ()
(interactive)
(switch-to-buffer "*Help*")
(erase-buffer)
(insert-file (expand-file-name "~/lib/fkeys.help"))
(message "Type C-x b <nl> to remove help window."))
(define-key global-map [f12] 'function-key-help)
And it works perfectly in my Emacs 23 setup.
It is hard to say what your problem might be without more information, like is it all your keybindings or just one or two that do not work. I will hazard a guess that it is the last two ([up] and [down]). In those cases the on-line documentation below seems to indicate that you might be shadowing the global definitions with local ones defined by the mode.
global-set-key is an interactive
compiled Lisp function in `subr.el'.
(global-set-key key command)
Give key a global binding as command.
command is the command definition to
use; usually it is a symbol naming an
interactively-callable function. key
is a key sequence; noninteractively,
it is a string or vector of characters
or event types, and non-ASCII
characters with codes above 127 (such
as ISO Latin-1) can be included if you
use a vector.
Note that if key has a local binding
in the current buffer, that local
binding will continue to shadow any
global binding that you make with this
function.

How do I indent my code in Emacs by 4 spaces intead of 2 for a bunch of files?

What is a more sane, automatic solution to tabbing my code by 4 spaces for a bunch of files? How do I make sure that tabify does not affect perldoc?
Well, you'll need this
(setq-default tab-width 4)
Then
C-x h
M-x indent-region
This sounds very similar to this other stack overflow question.
I had massive issues with this: This is the solution I came up with for a 3-spaces rule.
;;;; Tab settings ;;;;
;Tab width is 3
(setq tab-width 3)
;Tab width is 3 by default..
(setq-default tab-width 3)
;Use spaces always.
(setq indent-tabs-mode nil)
;Jump by 3.
(setq c-basic-offset 3)
;this defaulted to 4 and had to be reset to 3.
(setq perl-indent-level 3)
;Tab stop list out to col 60
;Manually set by x3
(setq tab-stop-list '(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60))
You should look up the documentation for the mode you are using (e.g. Lisp mode, C mode, Perl mode) for setting up the desired indentation and for reindenting a region (e.g. in SLIME, this is done with C-M-\).
My cperl-mode seems to indent (or rather, not indent) POD fine, as long as it has a newline before the =head1 or =pod. perlpod says:
Without that empty line before the "=head1", many translators wouldn't have recognized the "=head1" as starting a Pod block.