emacs 使用积累1 c++-header-common.el c++-header.el kreatv-cc-style.el kreatv-compile.el

  

c++-header-common.el

;; Kreatel C++ Headers

 

(defun kreatel-common-insert-header (filename text)

  (insert

   (concat "// Copyright (c) "

           (format-time-string "%Y")

           " Motorola Mobility, Inc. All rights reserved.\n"

           "// This program is confidential and proprietary to Motorola Mobility, Inc and\n"

           "// may not be copied, reproduced, disclosed to others, published or used, in\n"

           "// whole or in part, without the expressed prior written permission of Motorola\n"

           "// Mobility, Inc.\n"

           "\n")))

 

(defun kreatel-separator ()

 (interactive)

 (insert (concat "// -----------------------------------"

          "-----------------------------------------\n")))

 

 

(provide 'kreatel-c++-header-common)

 

 

 

c++-header.el

;; Kreatel C++ Headers

 

(require 'kreatel-c++-header-common "c++-header-common.el")

 

(defun kreatel-insert-header ()

  (interactive)

  (kreatel-common-insert-header

   (file-name-nondirectory (buffer-file-name)) ""))

 

(defun kreatel-insert-header-stuff ()

  (interactive)

  (let ((filename

         (upcase (file-name-nondirectory (buffer-file-name)))))

    (while (string-match "\\.\\|/" filename)

      (setq filename (replace-match "_" t t filename)))

    (save-excursion

      (goto-char (point-min))

      (kreatel-insert-header)

      (insert (concat "#ifndef " filename "\n"))

      (insert (concat "#define " filename "\n\n"))

      (goto-char (point-max))

      (insert (concat "\n#endif\n")))))

 

 

(provide 'kreatel-c++-header)

 

 

 

 

 

kreatv-cc-style.el

;;; This file defines an Emacs cc-mode style called "kreatv" that follows the

;;; KreaTV coding standard.

 

(c-add-style

 "kreatv"

 '("gnu"

   (indent-tabs-mode . nil)

   (c-basic-offset . 2)

   (c-block-comment-prefix . "* ")

   (c-hanging-colons-alist

    (case-label after)

    (label after))

   (c-cleanup-list

    empty-defun-braces

    defun-close-semi

    list-close-comma

    scope-operator)

   (c-hanging-semi&comma-criteria

    c-semi&comma-no-newlines-before-nonblanks

    c-semi&comma-no-newlines-for-oneline-inliners

    c-semi&comma-inside-parenlist)

   (c-offsets-alist

    (innamespace . 0)

    (inclass . +)

    (inline-open . 0)

    (statement-cont . +)

    (substatement-open . 0)

    (arglist-intro . +)

    (arglist-close . +))

   (c-hanging-braces-alist

    (substatement-open after)

    (defun-open before after)

    (class-open before after))))

 

(provide 'kreatv-cc-style)

 

 

 

 

kreatv-compile.el

;;; Provides suitable compile commands for KreaTV.

;;;

;;; Example key bindings to add to .emacs or similar:

;;;

;;; (global-set-key [f5] 'compile)

;;; (global-set-key [f6] 'kreatv-compile-clean)

;;; (global-set-key [f7] 'kreatv-check-coding-style)

 

(require 'kreatv-env)

 

(set-default 'compile-command "make local_all NO_SCU=1")

(set-default 'kreatv-compile-clean-command "make local_clean")

 

(defun kreatv-compile-directory ()

  "Get the relative path to a directory where it is suitable start a compile."

  (cond

   ((file-exists-p "Makefile") nil)

   ((file-exists-p "../Makefile") "..")

   ((file-exists-p "../../Makefile") "../..")

   (t nil)))

 

(defun kreatv-set-default-compile-command ()

  (let ((path (kreatv-compile-directory))

(command "make"))

    (when path (setq command (concat "cd " path " && " command)))

    (set (make-local-variable 'compile-command)

         (concat command " local_all NO_SCU=1"))

    (set (make-local-variable 'kreatv-compile-clean-command)

         (concat command " local_clean"))))

 

(defun kreatv-compile-clean ()

  "Run make local_clean for the current component"

  (interactive)

  (let ((compile-command kreatv-compile-clean-command))

    (call-interactively 'compile)))

 

(defun kreatv-check-coding-style ()

  "Run the script to check coding style"

  (interactive)

  ; Shadow compile-command to avoid compile setting global variable to

  ; .../check-coding-style, overriding user setting.

  (let (compile-command)

    (compile (concat kreatv-tools-directory "/bin/check-coding-style "

    (kreatv-compile-directory)))))

 

(add-hook 'c-mode-common-hook 'kreatv-set-default-compile-command)

 

(provide 'kreatv-compile)

 

 

 

 

 

kreatv-copyright.el

;;; Load this file to keep the copyright years in source code files up to date

;;; automatically.

 

(defun kreatv-copyright-parse-years (string)

  "Parse a string containing years (example: 2003, 2005, 2008-2010) into a list

of years in reverse order (example: (2010 2009 2008 2005 2003))."

  (save-match-data

    (setq string (replace-regexp-in-string "[ \t]" "" string))

    (sort (apply 'nconc

                 (mapcar (lambda (x)

                           (let ((y (mapcar 'string-to-number

                                            (split-string x "-"))))

                             (if (= (length y) 1)

                                 y

                               (number-sequence (car y) (cadr y)))))

                         (split-string string ",")))

          '>)))

 

(defun kreatv-copyright-intervalize (numbers)

  "(5 3 2 1) --> ((1 . 3) (5 . 5))"

  (let (result

        (prev most-positive-fixnum))

    (dolist (x numbers result)

      (if (= x (1- prev))

          (setcar (car result) x)

        (setq result (cons (cons x x) result)))

      (setq prev x))))

 

(defun kreatv-copyright-format-years (years)

  "Format a reverse list of years into a string."

  (mapconcat (lambda (x)

               (if (= (car x) (cdr x))

                   (format "%d" (car x))

                 (format "%d-%d" (car x) (cdr x))))

             (kreatv-copyright-intervalize years)

             ", "))

 

(defun kreatv-copyright-current-year ()

  "Return current year as an integer."

  (nth 5 (decode-time)))

 

(defun kreatv-copyright-format-copyright-row (years)

  (format

   "Copyright (c) %s Motorola Mobility, Inc. All rights reserved."

   years))

 

(defun kreatv-copyright-comment-start ()

  (cond ((eq major-mode 'c-mode) "// ")

        ((eq major-mode 'emacs-lisp-mode) ";;; ")

        (t comment-start)))

 

(defun kreatv-copyright-format-blurb ()

  "This program is confidential and proprietary to Motorola Mobility, Inc and

may not be copied, reproduced, disclosed to others, published or used, in

whole or in part, without the expressed prior written permission of Motorola

Mobility, Inc.")

 

;; This regexp matches a "/* */", "//", ";" or "#" style comment (excluding any

;; shebang line).

(defvar kreatv-copyright-top-header-re

  "^\\(#![^\n]*\n+\\)?\\(/\\*\\(\\(.\\|\n\\)*?\\)\\*/\n\\|\\(\\(//\\|[;#]\\)\\(\\(.\\|\n\\)*?\\)\n\\)+\\)")

 

;; This regexp matches an old-style C++ comment. Subexpression 2 contains C or

;; C++ (or nil) and subexpression 6 contains the copyright row that we want to

;; save.

(defvar kreatv-copyright-old-style-c++-top-header-re

  "^/\\* *\\(-\\*- *[Mm]ode: *\\([Cc]\\(\\|\\+\\+\\)\\);.*?-\\*- *\n\\)?[ *\n]+-+[ *\n]+\\([A-Za-z0-9_/]*?\.\\(h\\|c\\|cpp\\)\\)?[ *\n]+\\(Copyright.*?\\)\n[ *\n]*-+[ *\n]+\\*/")

 

(defun kreatv-copyright-fix-old-style-comment ()

  (let ((orig-point (point)))

    (goto-char (point-min))

    (when (looking-at kreatv-copyright-old-style-c++-top-header-re)

      (let ((mode-type (or (match-string 2) ""))

            (copyright-text (match-string 6)))

        (replace-match

         (format (if (and (string= (downcase mode-type) "c")

                          (string= (file-name-extension buffer-file-name) "h"))

                     "// -*- Mode: C -*-\n//\n// %s"

                   "// %s")

                 copyright-text))))))

 

(defun kreatv-copyright-update-copyright-years ()

  (let ((current-year (kreatv-copyright-current-year))

        (ryears (kreatv-copyright-parse-years (match-string 1))))

    (unless (eq (car-safe ryears) current-year)

      (replace-match

       (kreatv-copyright-format-copyright-row

        (kreatv-copyright-format-years

         (cons current-year ryears)))))))

 

(defun kreatv-copyright-find-copyright-row ()

  (goto-char (point-max))

  (search-backward-regexp

   "Copyright +([cC]) +\\([0-9, -]+\\).*Motorola Mobility.*$"

   nil 'noerror))

 

(defun kreatv-copyright-update-copyright ()

  (goto-char (point-min))

  (if (kreatv-copyright-find-copyright-row)

      (kreatv-copyright-update-copyright-years)

    ;; No Motorola Mobility copyright row. Add one if there's another

    ;; Motorola or Kreatel copyright row. (If there isn't, it's probably

    ;; too hard to figure out what to do.)

    (goto-char (point-max))

    (when (search-backward-regexp

           "^\\(.*\\)Copyright +([cC]).*\\(Motorola\\|Kreatel\\).*$"

           nil 'noerror)

      (replace-match

       (format "\\&\n\\1%s"

               (kreatv-copyright-format-copyright-row

                (kreatv-copyright-current-year))))

      ;; Redo the match to set up the match state to point to the recently

      ;; added Motorola Mobility row.

      (kreatv-copyright-find-copyright-row)

      (kreatv-copyright-update-copyright-years))))

 

(defun kreatv-copyright-find-blurb ()

  (goto-char (point-min))

  (search-forward-regexp

   "This program is confidential and proprietary to Motorola Mobility, Inc"

   nil 'noerror))

 

(defun kreatv-copyright-add-blurb ()

  (when (and (not (kreatv-copyright-find-blurb))

             (search-backward-regexp

              "^\\(.*\\)Copyright +([cC]).*Motorola Mobility.*$"

              nil 'noerror))

    (forward-line 1)

    (set-mark (point))

    (insert (format "\n%s\n" (kreatv-copyright-format-blurb)))

    (forward-line -1)

    (string-rectangle (mark) (point) (match-string 1))))

 

(defun kreatv-copyright-symbol-bound-and-true (mode)

  (and (boundp mode) (symbol-value mode)))

 

(defun kreatv-copyright-should-update ()

  (not (or (kreatv-copyright-symbol-bound-and-true 'emerge-mode)

           (kreatv-copyright-symbol-bound-and-true 'smerge-mode))))

 

(defun kreatv-copyright-update-header ()

  (when (and (not undo-in-progress) (kreatv-copyright-should-update))

    (save-match-data

      (save-excursion

        (let ((orig-point (point)))

          (goto-char (point-min))

          (when (and (looking-at kreatv-copyright-top-header-re)

                     (> orig-point (match-end 0)))

            (save-restriction

              (narrow-to-region (match-beginning 0) (match-end 0))

              ;; Now we are only looking at the top comment.

              (kreatv-copyright-fix-old-style-comment)

              (kreatv-copyright-update-copyright)

              (kreatv-copyright-add-blurb)

              (delete-trailing-whitespace))))))))

 

(defun kreatv-copyright-update-copyright-soon ()

  ;; Queue a call to `kreatv-copyright-update-header'. We can't call

  ;; `kreatv-copyright-update-header' immediately from `first-change-hook'

  ;; because some editor commands (for instance `open-line' and

  ;; `transpose-chars') save the point location before doing buffer

  ;; modifications and then restores point to the saved location before doing

  ;; more modifications. The saved location may then refer to the wrong

  ;; location if `first-change-hook' has modified the buffer.

  (run-at-time 0 nil 'kreatv-copyright-update-header))

 

(defun kreatv-copyright-activate-for-this-buffer ()

  (add-hook

   'first-change-hook 'kreatv-copyright-update-copyright-soon nil 'local))

 

(defun kreatv-add-copyright ()

  "Add a copyright header at the beginning of the buffer."

  (interactive)

  (save-excursion

    (goto-char (point-min))

    (insert (format "%s\n\n%s\n\n"

                    (kreatv-copyright-format-copyright-row

                     (kreatv-copyright-current-year))

                    (kreatv-copyright-format-blurb)))

    (previous-line 2)

    (string-rectangle (point-min) (point) (kreatv-copyright-comment-start))

 

    (when (search-backward-regexp " $" nil 'noerror)

      (replace-match ""))))

 

;; Update copyright in all cc-mode modes as well as Emacs Lisp, Perl, Python

;; and sh modes.

(add-hook 'c-mode-common-hook 'kreatv-copyright-activate-for-this-buffer)

(add-hook 'emacs-lisp-mode-hook 'kreatv-copyright-activate-for-this-buffer)

(add-hook 'perl-mode-hook 'kreatv-copyright-activate-for-this-buffer)

(add-hook 'python-mode-hook 'kreatv-copyright-activate-for-this-buffer)

(add-hook 'sh-mode-hook 'kreatv-copyright-activate-for-this-buffer)

 

(provide 'kreatv-copyright)

 

 

 

kreatv-env.el

;;; Default values for environment settings

 

(set-default 'kreatv-tools-directory "/home/tools")

 

(provide 'kreatv-env)

 

 

kreatv-fcode.el

 ;;; This file provides a fcode function which can be used to integrate

;;; the command devtools/bin/fcode into emacs.

 

(require 'kreatv-env)

 

(defun fcode (string directory)

  (interactive

   (list

    (read-string "Search string: " (thing-at-point 'symbol))

    (read-directory-name "Directory: ")))

 

  (let ((grep-use-null-device nil))

    (grep (concat kreatv-tools-directory "/bin/fcode -n -p " directory

                  " '" (replace-regexp-in-string "'" "'\"'\"'" string) "'"))))

 

(provide 'kreatv-fcode)

 

 

 

 kreatv-gtags.el

(when (require 'gtags "/usr/share/gtags/gtags.el" 'noerror)

  (defun gtags-update-sentinel (process event)

    (if (= (process-exit-status process) 0)

        (message "Updating GTAGS database...done")

      (message "Updating GTAGS database...FAILED")))

 

  (defun gtags-update ()

    (interactive)

    (message "Updating GTAGS database...")

    (set-process-sentinel

     (start-process "gtags-update" nil "gtags-update")

     'gtags-update-sentinel)))

 

(provide 'kreatv-gtags)

 

 

kreatv-recommended.el

;;; This file contains some Emacs settings that are recommended for KreaTV

;;; development.

;;;

;;; Load it like this:

;;;

;;; (add-to-list 'load-path "/home/tools/elisp")

;;; (require 'kreatv-recommended)

;;;

;;; The idea is to keep this file quite conservative so that you can load it

;;; without fear of clobbering your settings too much. For instance, it doesn't

;;; define any key bindings.

;;;

;;; However, here are some suggested key bindings that you can add to your

;;; ~/.emacs or similar:

;;;

;;; (global-set-key (kbd "M-,") 'gtags-find-rtag)

;;; (global-set-key (kbd "M-.") 'gtags-find-tag)

;;; (global-set-key (kbd "M-g M-f") 'gtags-find-file)

;;; (global-set-key (kbd "M-g M-s") 'gtags-find-symbol)

;;; (global-set-key (kbd "M-g M-u") 'gtags-update)

;;; (global-set-key (kbd "M-g f") 'gtags-find-file)

;;; (global-set-key (kbd "M-g s") 'gtags-find-symbol)

;;; (global-set-key (kbd "M-g u") 'gtags-update)

;;; (global-set-key (kbd "<f11>") 'delete-trailing-whitespace-and-keep-doing-so)

;;; (global-set-key (kbd "<C-f11>") 'toggle-auto-remove-trailing-whitespace))

 

;; KreaTV coding style.

(require 'kreatv-cc-style)

 

;; Use the kreatv C/C++ style. See

;; <http://twiki.mot.com/bin/view/KreaTV/CppCodingStandard>.

(setq c-default-style "kreatv")

 

;; Don't indent with tabs.

(setq indent-tabs-mode nil)

 

(defun kreatv-cc-mode-init ()

  ;; Add missing final newline automatically when saving a C/C++ file.

  (set (make-local-variable 'require-final-newline) t))

(add-hook 'c-mode-common-hook 'kreatv-cc-mode-init)

 

;; Remove inadvertently added trailing whitespace automatically when saving.

(require 'no-trailing-whitespace)

 

;; Update year in the copyright header automatically.

(require 'kreatv-copyright)

 

;; Support for GNU Global. See

;; <http://twiki.mot.com/bin/view/KreaTV/GnuGlobal>.

(require 'kreatv-gtags)

 

;; Use C++ mode for .h files.

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

 

;; markdown-mode

(autoload

  'markdown-mode "markdown-mode"

  "Major mode for editing Markdown files" t)

(add-to-list 'auto-mode-alist '("\\.md" . markdown-mode))

(add-to-list 'auto-mode-alist '("\\.mmd" . markdown-mode))

 

(provide 'kreatv-recommended)

 

 

 

no-trailing-whitespace.el

;;; no-trailing-whitespace -- keep your source free from trailing whitespace

;;

;; Copyright (C) 2009-2010 Joel Rosdahl

;;

;; Redistribution and use in source and binary forms, with or without

;; modification, are permitted provided that the following conditions

;; are met:

;; 1. Redistributions of source code must retain the above copyright

;;    notice, this list of conditions and the following disclaimer.

;; 2. Redistributions in binary form must reproduce the above copyright

;;    notice, this list of conditions and the following disclaimer in the

;;    documentation and/or other materials provided with the distribution.

;; 3. Neither the name of the author nor the names of its contributors

;;    may be used to endorse or promote products derived from this software

;;    without specific prior written permission.

;;

;; ============================================================================

;;

;; This file installs some hooks so that you won't inadvertently add any

;; trailing whitespace to your code. If no trailing whitespace exists in a file

;; when it is opened, all trailing whitespace is removed when the buffer is

;; saved, so that files without trailing whitespace stay that way. Thus, the

;; behaviour is conservative: if there is any preexisting trailing whitespace

;; in the file, it is kept (along with any newly introduced trailing

;; whitespace).

;;

;; Two commands and one variable are also provided:

;;

;; - The buffer-local `auto-remove-trailing-whitespace' variable says whether

;;   trailing whitespace will be removed when saving the buffer. The variable

;;   is set to t when a file without trailing whitespace is loaded.

;;

;; - The `toggle-auto-remove-trailing-whitespace' command toggles

;;   `auto-remove-trailing-whitespace'. Use this command if you want to add

;;   trailing whitespace to a file without preexisting trailing whitespace.

;;

;; - The `delete-trailing-whitespace-and-keep-doing-so' command deletes

;;   trailing whitespace in the current buffer and sets

;;   `auto-remove-trailing-whitespace' to t.

;;

;;; INSTALLATION

;;; ============

;;

;; Put

;;

;;   (require 'no-trailing-whitespace)

;;

;; or (if needed)

;;

;;   (require 'no-trailing-whitespace "/path/to/no-trailing-whitespace.el")

;;

;; in your .emacs file.

;;

;; You may also want to add some key bindings, for example:

;;

;;   (global-set-key (kbd "<f11>") 'delete-trailing-whitespace-and-keep-doing-so)

;;   (global-set-key (kbd "<C-f11>") 'toggle-auto-remove-trailing-whitespace)

 

(defvar auto-remove-trailing-whitespace nil

  "*Whether the maybe-remove-trailing-whitespace function should

remove trailing whitespace.")

(make-variable-buffer-local 'auto-remove-trailing-whitespace)

 

(defun toggle-auto-remove-trailing-whitespace ()

  "Toggle whether trailing whitespace should be deleted when saving the buffer."

  (interactive)

  (make-local-variable 'auto-remove-trailing-whitespace)

  (setq auto-remove-trailing-whitespace (not auto-remove-trailing-whitespace))

  (message

   "%semoving trailing whitespace when saving."

   (if auto-remove-trailing-whitespace "R" "Not r")))

 

(defun buffer-contains-trailing-whitespace ()

  (save-excursion

    (goto-char (point-min))

    (search-forward-regexp "[ \r\t]$" nil 'noerror)))

 

(defun set-auto-remove-trailing-whitespace ()

  (if (not (buffer-contains-trailing-whitespace))

      (setq auto-remove-trailing-whitespace t)

    (message (concat "Warning: File contains trailing whitespace;"

                     " will not automatically remove"))))

 

(defun maybe-remove-trailing-whitespace ()

  "Remove trailing whitespace from all lines in the current

buffer if and only if auto-remove-trailing-whitespace is non-nil."

  (when auto-remove-trailing-whitespace

    (delete-trailing-whitespace))

  nil) ; Return nil --> don't stop calling other write file hooks.

 

(defun delete-trailing-whitespace-and-keep-doing-so ()

  "Delete trailing whitespace in the current buffer and make sure that it also

is deleted when saving the buffer."

  (interactive)

  (delete-trailing-whitespace)

  (setq auto-remove-trailing-whitespace t))

 

(add-hook 'find-file-hook 'set-auto-remove-trailing-whitespace)

(add-hook 'write-file-functions 'maybe-remove-trailing-whitespace)

 

(provide 'no-trailing-whitespace)

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值