From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7020 invoked by alias); 14 Apr 2012 04:43:55 -0000 Received: (qmail 7010 invoked by uid 22791); 14 Apr 2012 04:43:54 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL,BAYES_00,FROM_12LTRDOM,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 14 Apr 2012 04:43:40 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1SIupm-00020W-Ti from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Fri, 13 Apr 2012 21:43:38 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 13 Apr 2012 21:43:38 -0700 Received: from localhost.localdomain (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.1.289.1; Fri, 13 Apr 2012 21:43:37 -0700 From: Yao Qi To: Subject: [PATCH] Check code stype in Emacs: gdb-code-style.el Date: Sat, 14 Apr 2012 07:46:00 -0000 Message-ID: <1334378614-13787-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00391.txt.bz2 Hi, gdb-code-style.el gives some checks, and highlight corresponding parts if they are violations on a certain rule or convention in gdb development. So far, it only has two, and I'd like to push more, if it is the right way to go. Ideally, I hope these checks can go to gdb/.dir-locals.el, as they apply when people open gdb source files automatically. However, the repeated warning when opening files force me to think about moving them to a separate .el file, and give contributors to decide use this .el or not. Some of the rules I am using are from the lesson I learned from the review to my patches, such as missing space or superfluous spaces. I am sure it is useful, especially to new contributors. gdb: * gdb-code-style.el: New. --- gdb/gdb-code-style.el | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 gdb/gdb-code-style.el diff --git a/gdb/gdb-code-style.el b/gdb/gdb-code-style.el new file mode 100644 index 0000000..5919e3d --- /dev/null +++ b/gdb/gdb-code-style.el @@ -0,0 +1,35 @@ +;; Emacs settings to check various code styles. +;; Copyright (C) 2012 Free Software Foundation, Inc. + +;; 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 +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;; These hooks defined in this file provide some code style checks in +;; Emacs. You can load it in your ~/.emacs, +;; (load-file "~/$(GDB_SOURCE)/gdb/gdb-code-style.el") + +;; Don't use these functions. Their alternatives are better. This list +;; of functions is from ARI rules. +(defun gdb-fun-name-hook () + (font-lock-add-keywords + nil + '(("\\<\\(\\(xasprintf\\|abort\\|vasprintf\\|strerror\\|strdup\\|asprintf\\|sprintf\\)[ ]*\(\\)" 1 font-lock-warning-face t)))) +(add-hook 'c-mode-common-hook 'gdb-fun-name-hook) + +;; Don't include these files directly. +(defun gdb-include-hook () + (font-lock-add-keywords + nil + '(("\\\\)" 1 font-lock-warning-face t)))) + +(add-hook 'c-mode-common-hook 'gdb-include-hook) -- 1.7.0.4