4 Replies - 260 Views - Last Post: 01 August 2014 - 01:17 PM

#1 player1  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 19-April 14

Emacs giving me trouble

Posted 31 July 2014 - 10:19 PM

I wasn't sure where to post this, but since I am developing in HTML and PHP, I figured I could get some help here.

So anyways, I am starting to use Emacs and I love it so far. However one thing I have been trying to fix for the past couple hours is using TAB. Every time I hit tab (depending on which option I change in my .emacs file) it either only styles it for me, or I have to press TAB 3 times for it to indent 5 spaces. I hit TAB once, it doesn't do anything. I hit TAB a second time, it adds one space. I hit tab a third time, it indents 4 spaces (total of 5 spaces now). I have searched the internet for hours now and nothing is working and it's extremely frustrating to have very ugly and messy styled code.

This is my current .emacs file:

(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.
 '(ansi-color-names-vector ["black" "#d55e00" "#009e73" "#f8ec59" "#0072b2" "#cc79a7" "#56b4e9" "white"])
 '(custom-enabled-themes (quote (tsdh-dark)))
 '(electric-indent-mode 1)
 '(indent-tabs-mode nil)
 '(tab-always-indent nil)
 '(tab-width 4)
 '(transient-mark-mode t)
(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.
 )



Basically I want my TAB to work like any other text editor. I press TAB, it indents 4 spaces or an actual TAB and nothing else.

Any help is GREATLY appreciated as i'm on my last wits here!

This post has been edited by player1: 31 July 2014 - 10:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Emacs giving me trouble

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10567
  • View blog
  • Posts: 39,121
  • Joined: 27-December 08

Re: Emacs giving me trouble

Posted 31 July 2014 - 10:25 PM

Moved to Linux/Unix.
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,106
  • Joined: 19-March 11

Re: Emacs giving me trouble

Posted 31 July 2014 - 11:56 PM

Before I go into this, I should say that many people consider your request to be a breaking of good functionality. You might want to try to get used to the way emacs handles indents - for most languages, emacs is very good at getting the indent right. However, since you're wotking in PHP, I can see how this would be a problem. PHP and emacs are a sort of legendary problem... oddly enough, the people who are really good at customizing emcas never seem to have a yen to work in PHP. Have to ponder that a little.

Anyway. I'm not really an emacs guru, so this is a bit of guesswork and poking around. Keep a backup copy of your init file just in case.

I see some functions in your init that I don't recognize and aren't part of my EMACS installation. It might be that setting electric-indent-mode to nil, or setting one of the other indent settings to a non-nil value might do the trick.

If those fail, then fall back to existing functions. What you want is to bind the tab key to the tab-to-tab-stop command. This will indent to the next tab stop each time the tab key is pressed, which I think is what you're looking for. (it's ordinarily bound to M-i, so you can try it out)

If you add

(global-set-key (kbd "TAB") 'tab-to-tab-stop)


to your init file, probably after those tab functions that I don't recognize, good things might happen. If that fails, report back what happened, and include the version info on your emacs install, plus anything interesting that you've done to tweak your install, and we'll see if we can figure it out.
Was This Post Helpful? 0
  • +
  • -

#4 player1  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 19-April 14

Re: Emacs giving me trouble

Posted 01 August 2014 - 12:52 PM

Thanks for the response.

However, using that command (I don't think) didn't change anything. I did however try the M-i and it works exactly how I want my TAB to work (except it's 8 spaces for M-i instead of 4).

Basically I am just trying to get Emacs to work like any other editor (auto indent on a new line, and tab to indent).

As for the electric-indent mode, that is for auto indenting on a new line to stay in the current scope instead of pressing tab a few times every new line.

I am still playing with it and nothing seems to be changing it. Pressing TAB 3 times (as explained in OP) is the only way to get indentation (then having to backspace once to get 4 spaces)

EDIT:
After opening a c++ file, tabbing seems to stop working after indenting 2 spaces instead of 4 for some reason.

I think I am going to clear out my config file and start adding things one by one and post back

This post has been edited by player1: 01 August 2014 - 01:00 PM

Was This Post Helpful? 0
  • +
  • -

#5 player1  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 19-April 14

Re: Emacs giving me trouble

Posted 01 August 2014 - 01:17 PM

I can't edit my post for some reason, but I feel I am getting closer. Currently I have everything set up how I want it, except when using TAB, it stops at 2 spaces (and also auto-indents on a new line at 2 spaces instead of 4) and won't go further than that.

My current file is:

(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-tab-always-indent (quote other))
 '(electric-indent-mode t)
 '(indent-tabs-mode nil)
 '(setq-default indent-line-function t)
 '(tab-width 4))
(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.
 )


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1