;; used in both: C and C++ extensions (defun insert-template-func () (princ M_s1 (get-buffer (buffer-name))) (princ M_s2 (get-buffer (buffer-name))) (backward-char (length M_s2)) (indent-region (- (point) (length M_s1)) (+ (- (point) 1) (length M_s2)) nil) (indent-for-tab-command) ) ;; this will be quick-c-mode (defun my-c-extension () (defun for-loop-func () "loop macro"(interactive) (setq M_s1 "for ( ") (setq M_s2 " ;;)\n\t") (insert-template-func)) (defun while-loop-func () "loop macro"(interactive) (setq M_s1 "while ( ") (setq M_s2 " )\n\t") (insert-template-func)) (defun do-while-loop-func () "loop macro"(interactive) (setq M_s1 "do\n\t ;\nwhile( ") (setq M_s2 " );\n") (insert-template-func)) (defun if-statement-func () "loop macro"(interactive) (setq M_s1 "if ( ") (setq M_s2 " )\n\t ") (insert-template-func)) (defun if-else-statement-func () "loop macro"(interactive) (setq M_s1 "if ( ") (setq M_s2 " )\n\t ;\nelse\n\t") (insert-template-func)) (defun else-statement-func () "loop macro"(interactive) (setq M_s1 "else") (setq M_s2 "\n\t") (insert-template-func)) (defun brace-func () "brace macro"(interactive) (setq M_s1 "{\n\t") (setq M_s2 ";\n}\n") (insert-template-func)) (defun define-func () "cpp macro"(interactive) (setq M_s1 "#define ") (setq M_s2 "\n") (insert-template-func) ) (defun include-func () "cpp macro"(interactive) (setq M_s1 "#include<") (setq M_s2 ".h>\n") (insert-template-func) ) (defun main-func-func () "mainfunc macro"(interactive) (setq M_s1 "int main (int argc,char ** argv)\n{\n\t") (setq M_s2 ";\n\treturn 0;\n}\n/*end of main function of program*/\n") (insert-template-func) ) (defun func-insert-func () "function inserting macro" (interactive) (setq N_function_name (read-string "function name: " "" nil nil t)) (setq M_s1 (concat "" N_function_name "\n{\n\t")) (setq M_s2 (concat ";\n\treturn ;\n}\n/* end of function " N_function_name "*/\n")) (insert-template-func)) (defun typedef-struct-insert-func () "typedef-struct inserting f" (interactive) (setq N_function_name (read-string "structure name: " "" nil nil t)) (setq M_s1 (concat "typedef struct " N_function_name "_t\n{\n\t")) (setq M_s2 (concat ";\n} " N_function_name ";\n")) (insert-template-func)) (defun c-return() (interactive) (c-indent-line) (newline-and-indent)) (defun c-return-2() (interactive) (end-of-line) (c-indent-line) (newline-and-indent)) ;;tabindent (setq tab-width 4) (setq-default indent-tabs-mode t) (setq c-basic-offset 4) ;; hideshow (hs-minor-mode) (auto-fill-mode) ;; my hs controls (local-set-key [(control q)(left)] 'hs-hide-block) (local-set-key [(control q)(right)] 'hs-show-block) (local-set-key [(control q)(up)] 'hs-toggle-hiding) ;; my quick coding (local-set-key [(control q)(i)] `if-statement-func) (local-set-key [(control q)(I)] `if-else-statement-func) (local-set-key [(control q)(e)] `else-statement-func) (local-set-key [(control q)(f)] `for-loop-func) (local-set-key [(control q)(m)] `main-func-func) (local-set-key [(control q)(w)] `while-loop-func) (local-set-key [(control q)({)] `brace-func) (local-set-key [(control q)(s)] `typedef-struct-insert-func) (local-set-key [(control q)(d)] `do-while-loop-func) (local-set-key [(control q)(u)] `func-insert-func) (local-set-key [(control q)(\#)(d)] `define-func) (local-set-key [(control q)(\#)(i)] `include-func) (local-set-key [(control q)(13)] `c-return-2) (local-set-key [(control c)(c)] `uncomment-region); (local-set-key [13] 'c-return) ;;; RET with automatic indent (c-set-style "stroustrup") (imenu-add-to-menubar "imenu") (setnu-mode t) ) ;; end my c extension (defun my-c++-extension () (my-c-extension) (defun class-wizard-func () "C++ class" (interactive) (defun member-func-implement () (setq currpoint (point)) (goto-char (point-max)) (if (= nmembersimplemented 0) (princ (concat "/* implementing methods of class " N_class_name " */") (get-buffer (buffer-name)) )) (setq nmembersimplemented (+ nmembersimplemented 1)) (setq retstr "") (if (string= N_mem_type "int")(setq retstr "return 0;\n") ) (setq M_s1 (concat "\n" N_mem_type " " N_class_name "::" N_mem_name "\n{\n\n" retstr "}\n/* end of member function " N_mem_name " of class " N_class_name " */\n\n") ) (insert-template-func) (goto-char currpoint) ) (defun add-member () ;; print member name (setq N_mem_name (read-string "member name: " "" nil nil t)) (setq M_s1 (concat N_mem_type " " N_mem_name ";\n")) (insert-template-func) ;; if member is function implement it in the end of file (string-match "\(" N_mem_name) (if ( < (match-beginning 0) (length N_mem_name))(member-func-implement) ) ) (setq N_class_name (read-string "class name: " "" nil nil t)) (setq M_s1 (concat "class " N_class_name " ")) (setq M_s2 "") (insert-template-func) (setq N_inherit_name (read-string "inherits from: " "" nil nil t)) (if (string= N_inherit_name "") (setq M_s1 (concat N_inherit_name "\n{\n\t") ) (setq M_s1 (concat ":" N_inherit_name "\n{\n\t") ) ) (setq M_s2 (concat "\n}; \n/* " N_class_name " */ \n")) (insert-template-func) (setq M_s2 "") (setq nmembersimplemented 0 ) (setq N_mem_type (read-string "first private member type: " "" nil nil t)) (unless (string= N_mem_type "") (setq M_s1 "private:\n")(insert-template-func) ) (while (not (string= N_mem_type "") ) (add-member) ;; get next member (setq N_mem_type (read-string "next private member type: " "" nil nil t)) ) ;;as above, but for protected members (setq N_mem_type (read-string "first protected member type: " "" nil nil t)) (unless (string= N_mem_type "") (setq M_s1 "protected:\n")(insert-template-func) ) (while (not (string= N_mem_type "") ) (add-member) ;; get next member (setq N_mem_type (read-string "next protected member type: " "" nil nil t)) ) (setq M_s1 "public:\n")(insert-template-func) ;;for public members this is a little bit more complex, because ;;they can include constructors and destructors (setq N_mem_type (read-string "first parametrized constructor arguments (\"default\" will be added last): " "" nil nil t)) (while (not (string= N_mem_type "") ) (setq N_mem_name (concat N_class_name "(" N_mem_type ")")) (setq N_mem_type "" ) (setq M_s1 (concat N_mem_type " " N_mem_name ";\n")) (insert-template-func) (member-func-implement) ;; get next member (setq N_mem_type (read-string "args of next parametrised constructor: " "" nil nil t)) ) ;;add default constructor (setq N_mem_name (concat N_class_name "()")) (setq M_s1 (concat N_mem_type " " N_mem_name ";\n")) (insert-template-func) (member-func-implement) ;;add default destructor (setq N_mem_name (concat "~" N_class_name "()")) (setq M_s1 (concat N_mem_type " " N_mem_name ";\n")) (insert-template-func) (member-func-implement) ;;add private members (setq N_mem_type (read-string "first public member type: " "" nil nil t)) (while (not (string= N_mem_type "") ) (add-member) ;; get next member (setq N_mem_type (read-string "next next member type: " "" nil nil t)) ) );; class-wizard (defun smart-add-member () "member-adding" (interactive) ) (local-set-key [(control q)(C)] `class-wizard-func) (setnu-mode t) );;quick-c++ (add-hook 'c-mode-hook 'my-c-extension) (add-hook 'c++-mode-hook 'my-c++-extension)