unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Gary Wessle <phddas@yahoo.com>
Subject: insert new line at ";" C++
Date: 03 Oct 2006 06:12:52 +1000	[thread overview]
Message-ID: <m3lkny1np7.fsf@localhost.localdomain> (raw)

Hi

On a dual boot box, in one OS, I have the C++ mode working as I like
it, but now I am working with another OS which has its own emacs.

I remember reading that it is best to customize emacs through its own
customization interface "M-x customize-variable..." rather than adding
lines in your .emacs file which so fare I have been successful in
doing until now. why, well, now I need to have emacs "in the C++" mode
to insert a new line once I type things like ")" "]" "}" ";" and the
like.
is there a way to do this without coping things from my old .emacs
file?

ok, here is my current .emacs file and below it is the section from my
old .emacs which does all the C++ goodies that I will eventually need
to incorporate into my new .emacs

****************************************************************
;; .emacs

;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)

;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
  (global-font-lock-mode t))

;; enable visual feedback on selections
;(setq transient-mark-mode t)

;; default to better frame titles
(setq frame-title-format
      (concat  "%b - emacs@" (system-name)))

;; default to unified diffs
(setq diff-switches "-u")

;; always end a file with a newline
;(setq require-final-newline 'query)

(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.
 '(column-number-mode t)
 '(default-major-mode (quote text-mode))
 '(display-time-24hr-format t)
 '(display-time-day-and-date t)
 '(display-time-mode t nil (time))
 '(inhibit-startup-message t)
 '(kill-whole-line t)
 '(make-backup-files nil)
 '(menu-bar-mode t)
 '(text-mode-hook (quote (flyspell-mode turn-on-auto-fill text-mode-hook-identify)))
 '(tool-bar-mode nil nil (tool-bar))
 '(visible-bell t))
(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.
 '(default ((t (:stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 119 :width normal :family "adobe-courier")))))

(put 'erase-buffer 'disabled nil)


;; *************************************************
;; *********** my manual add-on section ************
;; *************************************************

;; makes a vertical split along the horisontal line
(defun htv-horizontal-to-vertical ()
  (interactive)
  (let ((one-buf (window-buffer (selected-window)))
        (buf-point (point)))
    (other-window 1)
    (delete-other-windows)
    (split-window-horizontally)
    (switch-to-buffer one-buf)
    (goto-char buf-point)))

;; makes a vertical split along the horisontal line
(defun vth-vertical-to-horizontal ()
  (interactive)
  (let ((one-buf (window-buffer (selected-window)))
        (buf-point (point)))
    (other-window 1)
    (delete-other-windows)
    (split-window-vertically)
    (switch-to-buffer one-buf)
    (goto-char buf-point)))

;; don't show password
(add-hook 'comint-output-filter-functions
'comint-watch-for-password-prompt)

;; copying functions
(global-set-key "\C-cw" "\M-b\C-@\M-f\M-w") ; word under point
(global-set-key "\C-cl" "\C-a\C-@\C-e\M-w") ; line under point
(global-set-key "\C-cs" "\M-a\C-@\M-e\M-w") ; sentence under point
(global-set-key "\C-cp" "\M-h\C-f\M-w")     ; paragraph under point

;; cut all the ^M
(global-set-key [f10] 'cut-ctrlM)
(defun cut-ctrlM ()  
  "Cut all visible ^M."
  (interactive)
  (beginning-of-buffer)
  (while (search-forward "\r" nil t)
    (replace-match "" nil t))
  )

;; makes relavent files executable
(add-hook 'after-save-hook
       #'executable-make-buffer-file-executable-if-script-p)

;; hideshow for programming
(load-library "hideshow")
(add-hook 'c++-mode-hook 'hs-minor-mode)

;; key bindings
(windmove-default-keybindings)		;Shift-arrow moves focus
(global-set-key [f5] (kbd "M-h M-C-\\")) ;indent region according to mode
(global-set-key [f6] 'setnu-mode)      ;set-number use twice after C-y
(global-set-key "\C-x\C-b" 'buffer-menu) ;binds the key C-x C-b to buffer-menu
(global-set-key [f7] (kbd "M-h M-;")) ;comment region
(global-set-key [f11] 'compile)         ;compiles a program

;; hitting shift-f8 will save the current buffer with permission 700
(defun chmod-save ()
  "Save and chmod 700 current buffer"
  (interactive)
  (save-buffer)
  (setq command (concat "chmod 700 " (buffer-file-name)))
  (message "%s " command)
  (shell-command command)
  )
(global-set-key [(shift f8)] 'chmod-save)
****************************************************************
*************************** end ********************************
****************************************************************

here is my C++ goodies from my old .emacs

(load "~/.emacs-mc394")
...
(add-hook 'c++-mode-hook
          '(lambda ()
             (turn-on-auto-fill) ;;Insert a newline if line gets to long.
             (c-toggle-auto-state 1) ;;Make ; and { and } and : all electric
             (c-set-style "mc394-style"))) 

(add-hook 'c++-mode-hook 'setnu-mode)   ;line numbers
(add-hook 'c++-mode-hook 'bar-cursor-mode) ;cursor to a bar
(add-hook 'c++-mode-hook 'show-paren-mode) ;marrying brackets show

here is .emacs-mc394
****************************************************************
;; Modified by Mike Hvidsten from MC38J emacs file
;;  Feb. 4, 2004

(c-add-style "mc394-style"
             '("cc-mode"
               (c-basic-offset . 3)      ; In general, indent 3 spaces
               (c-hanging-braces-alist
                (defun-open after))      ; brace that opens a function definition
               (c-cleanup-list brace-else-brace
                               brace-elseif-brace
                               empty-defun-braces
                               defun-close-semi
                               scope-operator)
               (c-hanging-braces-alist
                ; These determine whether a newline appears before
                ; and/or after a brace in various situations.
                (brace-list-open)
                (block-open after)       ; statement block open brace
                (defun-open after)       ; brace that opens a function definition
                (substatement-open after); the brace that opens a substatement block
                (block-close . c-snug-do-while))
               (c-hanging-colons-alist
                (access-label after)) ; Newline after protected: or private:
               (c-hungry-delete-key t))) ; delete black space all at once

;; Variable should be t if we are running xemacs.
(defvar xemacs-p
  (string-match "XEmacs" emacs-version))

(if (not xemacs-p)
    (progn
      (global-font-lock-mode t)
       ; If using global-font-lock-mode, make control-L update colors
      (global-set-key "\C-l"
                      (function (lambda (arg) (interactive "P")
                                  (font-lock-fontify-block 100)
                                  (recenter arg))))))
(setq auto-mode-alist (append '(("\\.h$" . c++-mode)) auto-mode-alist)) 

             reply	other threads:[~2006-10-02 20:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-02 20:12 Gary Wessle [this message]
2006-10-02 20:37 ` insert new line at ";" C++ Gary Wessle
2006-10-03  7:35 ` Andreas Roehler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3lkny1np7.fsf@localhost.localdomain \
    --to=phddas@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).