summaryrefslogtreecommitdiffstats
path: root/ravi-init-cpp.el
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2013-12-27 05:13:46 (GMT)
committerRavikiran Rajagopal <aine.marina@gmail.com>2013-12-27 05:13:46 (GMT)
commit4c766b44845107e2f1dd4ef63bc33d91e8a19617 (patch)
treeca24820d2a6604b193dbd21cc0557b3cee15fc62 /ravi-init-cpp.el
parent57ff6d322d50bd27a50fb124abc4c17f0477c0e3 (diff)
downloaddotemacs-4c766b44845107e2f1dd4ef63bc33d91e8a19617.zip
dotemacs-4c766b44845107e2f1dd4ef63bc33d91e8a19617.tar.gz
dotemacs-4c766b44845107e2f1dd4ef63bc33d91e8a19617.tar.bz2
Handle different innamespace indents correctly
Diffstat (limited to 'ravi-init-cpp.el')
-rw-r--r--ravi-init-cpp.el200
1 files changed, 103 insertions, 97 deletions
diff --git a/ravi-init-cpp.el b/ravi-init-cpp.el
index 84c98bc..7157c17 100644
--- a/ravi-init-cpp.el
+++ b/ravi-init-cpp.el
@@ -1,9 +1,9 @@
;;; ravi-init-cpp.el --- C/C++ handling
-;; Copyright (C) 2013
+;; Copyright (C) 2013
;; Author: <ravi@nero.lan>
-;; Keywords:
+;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -57,31 +57,31 @@
(cond
((and arg (> (car arg) 4))
(let ((cmd (read-from-minibuffer
- "Buffer local compile command: "
- (funcall get-buffer-compile-command
- (or (file-relative-name (buffer-file-name)) ""))
- nil nil 'compile-history)))
+ "Buffer local compile command: "
+ (funcall get-buffer-compile-command
+ (or (file-relative-name (buffer-file-name)) ""))
+ nil nil 'compile-history)))
(cond ((equal cmd "")
- (kill-local-variable 'compile-command)
- (kill-local-variable 'compilation-directory))
- (t
- (set (make-local-variable 'compile-command) cmd)
- (set (make-local-variable 'compilation-directory)
- default-directory))))
+ (kill-local-variable 'compile-command)
+ (kill-local-variable 'compilation-directory))
+ (t
+ (set (make-local-variable 'compile-command) cmd)
+ (set (make-local-variable 'compilation-directory)
+ default-directory))))
(when (not (equal compile-command ""))
;; `compile' changes the default value of
;; compilation-directory but this is a buffer local
;; compilation
(let ((dirbak (default-value 'compilation-directory)))
- (compile compile-command)
- (setq-default compilation-directory dirbak))))
+ (compile compile-command)
+ (setq-default compilation-directory dirbak))))
((or (and arg (<= (car arg) 4))
- (equal compile-command ""))
+ (equal compile-command ""))
(setq-default compile-command (read-from-minibuffer
- "Compile command: "
- (if (equal compile-command "")
- "make " compile-command)
- nil nil 'compile-history))
+ "Compile command: "
+ (if (equal compile-command "")
+ "make " compile-command)
+ nil nil 'compile-history))
(setq-default compilation-directory default-directory)
(when (not (equal (default-value 'compile-command) ""))
(compile (default-value 'compile-command))))
@@ -92,29 +92,29 @@
(use-package cc-mode
:mode (("\\.h\\(h?\\|xx\\|pp\\)\\'" . c++-mode)
- ("\\.ccfg\\'" . c++-mode)
+ ("\\.ccfg\\'" . c++-mode)
("\\.m\\'" . c-mode)
("\\.mm\\'" . c++-mode))
:init
(progn
(use-package doxymacs
:load-path ,(ravi/emacs-file "site-lisp/doxymacs/lisp")
- :init
+ :init
(progn
- (doxymacs-mode)
- (setq doxymacs-file-comment-template
- '("/**" > n
- " * " (doxymacs-doxygen-command-char) "file" > n
- " * " > n
- " * " (doxymacs-doxygen-command-char) "brief "
- (p "Brief description of this file: ") > n
- " */" > n)
- )
- (setq doxymacs-external-xml-parser-executable
- (ravi/emacs-file "site-lisp/doxymacs/c/doxymacs_parser"))
- (setq doxymacs-use-external-xml-parser t)
- (setq doxymacs-command-character "\\")
- )
+ (doxymacs-mode)
+ (setq doxymacs-file-comment-template
+ '("/**" > n
+ " * " (doxymacs-doxygen-command-char) "file" > n
+ " * " > n
+ " * " (doxymacs-doxygen-command-char) "brief "
+ (p "Brief description of this file: ") > n
+ " */" > n)
+ )
+ (setq doxymacs-external-xml-parser-executable
+ (ravi/emacs-file "site-lisp/doxymacs/c/doxymacs_parser"))
+ (setq doxymacs-use-external-xml-parser t)
+ (setq doxymacs-command-character "\\")
+ )
)
(defvar printf-index 0)
@@ -174,10 +174,16 @@
(defun my-c++-mode-hook ()
(setq c-offsets-alist
- (append '((innamespace . (if (string-equal "ccfg" (file-name-extension (buffer-file-name))) 2 0) )
- (statement-cont . c-lineup-math)
- (inline-open . 0))
- c-offsets-alist))
+ (append '((statement-cont . c-lineup-math)
+ (inline-open . 0))
+ c-offsets-alist))
+ (let ((innamespaceindent (if (string-equal "ccfg" (file-name-extension (buffer-file-name))) 2 0))
+ )
+ (setq c-offsets-alist
+ (append `((innamespace . ,innamespaceindent)
+ )
+ c-offsets-alist))
+ )
(setq c-macro-cppflags "-x c++")
(setq c-macro-prompt-flag t)
@@ -193,38 +199,38 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(defun kde-header-protection-definable-string ()
(let* ((definablestring (concat "_" (ravi-random-ucn-string 6)) )
- (f (buffer-file-name))
- (parts (nreverse (split-string f "/")))
- (i)
- (first-iter t)
- (iters (min (length parts) kde-header-protection-parts-to-show)))
- (dotimes (i iters)
- (let ((part (pop parts)))
- (setq definablestring
- (concat
- (upcase (replace-regexp-in-string "[\\.-]" "_" part))
- (if (not first-iter) "_" "")
- definablestring
- )
- )
- (setq first-iter nil)
- )
- )
- definablestring
- )
+ (f (buffer-file-name))
+ (parts (nreverse (split-string f "/")))
+ (i)
+ (first-iter t)
+ (iters (min (length parts) kde-header-protection-parts-to-show)))
+ (dotimes (i iters)
+ (let ((part (pop parts)))
+ (setq definablestring
+ (concat
+ (upcase (replace-regexp-in-string "[\\.-]" "_" part))
+ (if (not first-iter) "_" "")
+ definablestring
+ )
+ )
+ (setq first-iter nil)
+ )
+ )
+ definablestring
+ )
)
;; Creates the ifndef/define/endif statements necessary for a header file
(defun header-protection ()
(interactive)
(let ((s (kde-header-protection-definable-string)))
- (save-excursion
- (goto-char (point-min))
- (insert "#ifndef " s "\n#define " s "\n\n")
- (goto-char (point-max))
- (insert "\n#endif\n")
- )
- )
+ (save-excursion
+ (goto-char (point-min))
+ (insert "#ifndef " s "\n#define " s "\n\n")
+ (goto-char (point-max))
+ (insert "\n#endif\n")
+ )
+ )
)
(defun ravi-start-c++-header ()
@@ -237,16 +243,16 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(beginning-of-buffer)
(save-excursion
- (let ((start (point-min))
- (end)
- )
- (setq comment-style 'box)
- (goto-char start)
- (insert (ravi-license-header))
- (setq end (point))
- (comment-region start end)
- )
- )
+ (let ((start (point-min))
+ (end)
+ )
+ (setq comment-style 'box)
+ (goto-char start)
+ (insert (ravi-license-header))
+ (setq end (point))
+ (comment-region start end)
+ )
+ )
(end-of-buffer)
(next-line -3)
@@ -261,24 +267,24 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(defun ravi-license-insert ()
(progn
- (let ((start (point-min))
- (end)
- )
- (setq comment-style 'box)
- (goto-char start)
- (insert (ravi-license-header))
- (insert "\n")
- (setq end (point))
- (comment-region start end)
- )
- )
+ (let ((start (point-min))
+ (end)
+ )
+ (setq comment-style 'box)
+ (goto-char start)
+ (insert (ravi-license-header))
+ (insert "\n")
+ (setq end (point))
+ (comment-region start end)
+ )
+ )
)
(defun ravi-auto-insert-cpp ()
(progn
- (ravi-license-insert)
- (doxymacs-insert-file-comment)
- )
+ (ravi-license-insert)
+ (doxymacs-insert-file-comment)
+ )
)
)
@@ -288,12 +294,12 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(defun insert-comma (arg)
(interactive "*P")
(let* ((ch (char-after))
- (spacep (not (or (eq ch ? )
- (c-in-literal)
- arg))))
- (self-insert-command (prefix-numeric-value arg))
- (if spacep
- (insert " "))))
+ (spacep (not (or (eq ch ? )
+ (c-in-literal)
+ arg))))
+ (self-insert-command (prefix-numeric-value arg))
+ (if spacep
+ (insert " "))))
(defun insert-semicolon (arg)
(interactive "*P")
@@ -302,12 +308,12 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(bind-key "," 'insert-comma c-mode-base-map)
(bind-key ";" 'insert-semicolon c-mode-base-map)
-
+
(bind-key "<M-f8>" 'compile-dwim c-mode-base-map)
(bind-key "<M-f5>" 'hs-hide-block c-mode-base-map)
(bind-key "<M-f11>" 'hs-show-block c-mode-base-map)
-
+
(setq hide-ifdef-initially nil)
(bind-key "<S-f5>" 'hide-ifdef-block c-mode-base-map)
(bind-key "<S-f11>" 'show-ifdef-block c-mode-base-map)