help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"Tab-fix"


From: denebet
Subject: "Tab-fix"
Date: Tue, 22 Jul 2008 08:22:58 +0200
User-agent: KNode/0.10.9

I have put the stuff found at
<http://www.emacsblog.org/2007/03/12/tab-completion-everywhere/>
 in my .emacs to get autocompletion bound to tab in C(++) editing mode while
keeping the completion of file name in mini-buffers.

(defun indent-or-expand (arg)
  "Either indent according to mode, or expand the word preceding
point."
  (interactive "*P")
  (if (and
       (or (bobp) (= ?w (char-syntax (char-before))))
       (or (eobp) (not (= ?w (char-syntax (char-after))))))
      (dabbrev-expand arg)
    (indent-according-to-mode)))

(defun my-tab-fix ()
  (local-set-key [tab] 'indent-or-expand))
 
(add-hook 'c-mode-hook          'my-tab-fix)
(add-hook 'sh-mode-hook         'my-tab-fix)
(add-hook 'emacs-lisp-mode-hook 'my-tab-fix)

Unfortunately, it seems not to work, at least while editing cpp files.

Any idea ?

TIA

Alain
I give my complete .emacs below.

(setq load-path (cons "/usr/local/share/emacs/site-lisp" load-path))


(require 'tex-site)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(setq TeX-parse-self t) ; Enable parse on load.




;;(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
;; '(global-font-lock-mode t nil (font-lock)))
;;(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
;; )
;;(setq c-mode-hook '(lambda () (auto-fill-mode 1)))

;; And make text mode have auto-filling at column 80
(set-fill-column 80)
(defun my-c-mode-hook ()
  (auto-fill-mode)
)
(add-hook 'c-mode-hook 'my-c-mode-hook)

(setq magic-keys-mode t)
; To use this file, add this to your .emacs, uncommented :
(load "cc-engine.elc")

;; And make text mode have auto-filling at column 72
(set-fill-column 72)
(defun my-text-mode-hook ()
  (auto-fill-mode)
)

(add-hook 'text-mode-hook 'my-text-mode-hook)


;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/kdesdk-scripts")

;;(require 'kde-emacs)
;;(setq kde-full-name "Alain Bertrand")
;;(setq kde-email "address@hidden")

;;source-header
(defvar c++-source-extension-list '("c" "cc" "C" "cpp" "c++"))
(defvar c++-header-extension-list '("h" "hh" "H" "hpp"))

;; Default extension for c++ header files.
(defvar c++-default-header-ext "h")
;; Default extension for c++ source files.
(defvar c++-default-source-ext "cpp")
;; Default regexp for c++ header files.
(defvar c++-header-ext-regexp "\\.\\(hpp\\|h\\|\hh\\|H\\)$")
;; Default regexp for c++ source files.
(defvar c++-source-ext-regexp "\\.\\(cpp\\|c\\|\cc\\|C\\)$")

;; Switches between source/header files
(defun toggle-source-header()
  "Switches to the source buffer if currently in the header buffer and vice
versa."
  (interactive)
  (let ((buf (current-buffer))
        (name (file-name-nondirectory (buffer-file-name)))
        file
        offs)
    (setq offs (string-match c++-header-ext-regexp name))
    (if offs
        (let ((lst c++-source-extension-list)
              (ok nil)
              ext)
          (setq file (substring name 0 offs))
          (while (and lst (not ok))
            (setq ext (car lst))
            (if (file-exists-p (concat file "." ext))
                  (setq ok t))
            (setq lst (cdr lst)))
          (if ok
              (find-file (concat file "." ext))))
      (let ()
        (setq offs (string-match c++-source-ext-regexp name))
        (if offs
            (let ((lst c++-header-extension-list)
                  (ok nil)
                  ext)
              (setq file (substring name 0 offs))
              (while (and lst (not ok))
                (setq ext (car lst))
                (if (file-exists-p (concat file "." ext))
                    (setq ok t))
                (setq lst (cdr lst)))
              (if ok
                  (find-file (concat file "." ext)))))))))


;; Compilation: Set new window height, never ask for compile command, save
all files and sets new compile command.
'(compilation-window-height 10)
'(compilation-read-command nil)
'(compilation-ask-about-save nil)
'(compile-command "make -k")


;;mes options à moi
(global-set-key [(f6)] 'toggle-source-header)
(global-set-key [(f4)] 'compile)
(global-set-key [(f11)] 'indent-region)
(global-set-key [(f9)] 'ewd-insert-new-method)
;;(global-set-key [(tab)] 'agulbra-c++-tab)


(setq auto-mode-alist
(append '(("\\.h$"    . c++-mode)) auto-mode-alist))




;; Replace "yes or no" with y or n
(defun yes-or-no-p (arg)
  "An alias for y-or-n-p, because I hate having to type 'yes' or 'no'."
  (y-or-n-p arg))


(add-to-list 'load-path "~/elisp")

;;(setq load-path (cons "~/deb/" load-path))
;;(autoload 'dta-hook-up "desktopaid.elc" "Desktop Aid" t)
;;(dta-hook-up)
;;;
           (require 'windows)
           (win:startup-with-window)
           (define-key ctl-x-map "C" 'see-you-again)
;;;
          (autoload 'save-current-configuration "revive" "Save status" t)
          (autoload 'resume "revive" "Resume Emacs" t)
          (autoload 'wipe "revive" "Wipe Emacs" t)

          (define-key ctl-x-map "S" 'save-current-configuration)
          (define-key ctl-x-map "F" 'resume)
          (define-key ctl-x-map "K" 'wipe)
(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.
 '(TeX-save-query nil)
 '(fill-column 72))
(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.
 )

;;template module mostly used for auctex
(require 'template)
(template-initialize)
(put 'upcase-region 'disabled nil)


(defun indent-or-expand (arg)
  "Either indent according to mode, or expand the word preceding
point."
  (interactive "*P")
  (if (and
       (or (bobp) (= ?w (char-syntax (char-before))))
       (or (eobp) (not (= ?w (char-syntax (char-after))))))
      (dabbrev-expand arg)
    (indent-according-to-mode)))

(defun my-tab-fix ()
  (local-set-key [tab] 'indent-or-expand))
 
(add-hook 'c-mode-hook          'my-tab-fix)
(add-hook 'sh-mode-hook         'my-tab-fix)
(add-hook 'emacs-lisp-mode-hook 'my-tab-fix)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]