↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
历史版本PostgreSQL 8.1 已于 2010 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本。

第 44 章 PostgreSQL 编码约定

44.1. 格式 #

源代码格式使用 4 列制表宽度,并保留制表符(即,不会把制表符展开为空格)。 每个逻辑缩进层级都对应再增加一个制表位。布局规则(花括号位置等)遵循 BSD 约定。

尽管提交的补丁并不绝对必须遵循这些格式规则,但这样做是个好主意。 你的代码会经过 pgindent 处理,因此按另一套格式约定把它写得再漂亮也没有意义。

对于 Emacs,请把以下内容(或类似内容)加入 你的 ~/.emacs 初始化文件:

;; check for files with a path containing "postgres" or "pgsql"
(setq auto-mode-alist
  (cons '("\\(postgres\\|pgsql\\).*\\.[ch]\\'" . pgsql-c-mode)
        auto-mode-alist))
(setq auto-mode-alist
  (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode)
        auto-mode-alist))

(defun pgsql-c-mode ()
  ;; sets up formatting for PostgreSQL C code
  (interactive)
  (c-mode)
  (setq-default tab-width 4)
  (c-set-style "bsd")             ; set c-basic-offset to 4, plus other stuff
  (c-set-offset 'case-label '+)   ; tweak case indent to match PG custom
  (setq indent-tabs-mode t))      ; make sure we keep tabs when indenting

对于 vi,你的 ~/.vimrc 或等价的文件应包含以下内容:

set tabstop=4

或者在 vi 中等效地使用

:set ts=4

文本浏览工具 more 和 less 可以这样调用:

more -x4
less -x4

以便正确显示制表符。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。