1

every time I add a new line, it would indent automatically but it indents 2 spaces, not 4 spaces. Below is my .emacs snippet.

(defun make-vline-xpm (width height color &optional lor)
  (let* ((w width)
         (h height)
         (s1 (concat "\"" (make-string w (string-to-char " ")) "\""))
         (s2 (cond
              ((eq lor 0)
               (concat "\"." (make-string (1- w) (string-to-char " ")) "\""))
              ((eq lor 1)
               (concat "\"" (make-string (1- w) (string-to-char " ")) ".\""))
              ((null lor)
               (concat "\"" (make-string (- (1- w)(/ (1- w) 2))(string-to-char " "))
                       "." (make-string (/ (1- w) 2)(string-to-char " ")) "\""))))
         (sa (concat s1 ",\n" s2 ",\n")))
    (eval `(concat "/* XPM */
static char * dot_vline_xpm[] = {
\"" (number-to-string w) " " (number-to-string h) " 2 1\",
\"  c None\",
\". c " color "\",\n"
,@(mapcar (lambda(x) sa)
          (make-list (1- (/ h 2)) 0))
s1 ",\n" s2 "};"
))))

(defvar indent-vline-img (make-vline-xpm 9 20 "#4D4D4D"))
(defun draw-indent-tab (beg end &optional color)
  (if window-system
      (set-text-properties
       beg end
       `(display (image
                  :type xpm
                  :data ,indent-vline-img
                  :pointer text
                  :ascent center
                  :mask (heuristic t))
                 rear-nonsticky (display)
                 fontified t))
    (compose-region
     beg end
     (prog1 "|"
       (set-text-properties beg end '(font-lock-face (:foreground "#4D4D4D"))))
     'decompose-region)))

(defun draw-indent-vline ()
  (interactive)
  (save-excursion
    (beginning-of-line)
    (let* ((i (current-indentation))
           (l (save-excursion
                (count-lines (point)
                             (forward-list)))))
      (while (> l 0)
        (let* ((p1 (progn (move-to-column i)(point)))
               (p2 (1+ p1)))
          (if (and (eq (get-byte p1) 32)
                   (save-excursion
                     (skip-chars-backward " ")(bolp)))
              (draw-indent-tab p1 p2))
          nil)
        (forward-line)
        (setq l (1- l))))))

(defun indent-vline-lisp ()
  (interactive)
  (funcall
   (lambda (x)
     (font-lock-add-keywords
      nil `((,x
             (0 (draw-indent-vline))))))
   "^[ \t]*[,`#'(]")
  (defadvice delete-char (after indent-vline activate compile)
    (save-excursion
      (let* ((p (point))
             (q (skip-chars-forward " "))
             (x (progn (skip-chars-backward " ")(bolp))))
        (if x
            (remove-text-properties p (+ p q) '(display)))))))

(defun indent-vline ()
  (interactive)
  (funcall
   (lambda (x)
     (font-lock-add-keywords
      nil `((,x
             (0 (if (save-excursion
                      (skip-chars-backward " ")(bolp))
                    (let* ((p1 (point))
                           (p2 (1+ p1)))
                      (if (or (null (eq (get-byte p1) 32))
                              (get-text-property p1 'display))
                          nil
                        (draw-indent-tab p1 p2)
                        nil))))))))
   "   \\( \\)")
  (defadvice delete-char (after indent-vline activate compile)
    (save-excursion
      (let* ((p (point))
             (q (skip-chars-forward " "))
             (x (progn (skip-chars-backward " ")(bolp))))
        (if x
            (remove-text-properties p (+ p q) '(display)))))))

I do not know lisp language. This .emscs is copied from others'. So my problem is how to set 4 space indent? I have tried to add below to my .emacs, but it does not work.

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
city
  • 2,036
  • 2
  • 32
  • 40
  • 1
    You haven't provided enough information. This Q&A might provide some illumination: http://stackoverflow.com/questions/6850351/emacs-indent-level-global-override – phils Jul 17 '13 at 22:30

1 Answers1

2

How about using custom-set-variables:

(custom-set-variables
    '(tab-width 4))
jh314
  • 27,144
  • 16
  • 62
  • 82
  • 2
    Those lines are potentially dangerous, as there cannot be more than one instance of `custom-set-variables` in init file. Since @city is not an expert in lisp, it would be better to advice the usage of M-x customize-variable tab-width – juanleon Jul 17 '13 at 15:54
  • 1
    @juanleon, both methods does not work....I do not why. thanks for your help any way. – city Jul 17 '13 at 18:45
  • 2
    It seems some other thing in your setup is changing your config... just start emacs as "emacs -q" and then eval `(setq-default indent-tabs-mode nil)` and `(setq-default tab-width 4)`. Then see if the problem remains. If it does not, you need to check the rest of your setup. – juanleon Jul 18 '13 at 06:43