Making emacs to highlight postgresql syntax by default

吃可爱长大的小学妹 提交于 2019-12-20 17:41:31

问题


I use emacs for editing my sql code. I work 99% of time on postgresql plpgsql code. All my files with extension .sql contain postgresql. I'm curious is there a way to set sql-highlight-postgres-keywords SQL highlighting default instead of ANSI SQL, because it's pretty annoying to switch mode every time I open a file.


回答1:


Usually in emacs, if you want to change the settings every time some mode is opened, you use a hook. Something similar to this should work:

(add-to-list 'auto-mode-alist
             '("\\.psql$" . (lambda ()
                              (sql-mode)
                              (sql-highlight-postgres-keywords))))



回答2:


If you need to work with different databases, rather than using a hook to always switch to PostgreSQL highlighting when you open a .sql file, you can use Emacs' file variables feature to set the product on a file-by-file basis.

For example, if the first line of your .sql file is

-- -*- mode: sql; sql-product: postgres; -*-

sql-mode will automatically use PostgreSQL highlighting.

Full details on Emacs file variables here (you can also set them in a block anywhere in the file), and the list of product names is probably eaiest found by doing M-x sql-set-product, backspacing the ansi default, and hitting TAB to see the completion list. Examples are "mysql", "oracle", "sqlite", etc (about a dozen in my install).



来源:https://stackoverflow.com/questions/4793900/making-emacs-to-highlight-postgresql-syntax-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!