在plsql-mode中,Emacs的对齐失败

时间:2011-11-22 20:50:44

标签: emacs plsql

我一直在PL/SQL mode上使用EmacsWiki,我对此感到非常满意。

但是当我尝试alignalign-current时,我发现了一个错误:

align: Wrong type argument: sequencep, plsql-align-rules-list

我尝试对齐的示例代码:

declare
  foo number;
  x number;
  y number;
begin
  foo :=     5;
  x := 123;
  y:=123;
end;

预期结果是:

declare
  foo number;
  x number;
  y number;
begin
  foo := 5;
  x   := 123;
  y   := 123;
end;

以下是plsql-mode代码的相关(我希望)部分:

;;;_  + Align

;; Should I make so that anything that is highlighted will line up?
;; Should we make a block anything inside ()?

(eval-and-compile

  (defcustom plsql-align-rules-list '()  ""
    :group 'plsql
    :type  'align-rules-list-type)

  ;; Should I make so that anything that is highlighted will line up?
  ;; Should we make a block anything inside ()?

  (when (condition-case nil
            (require 'align)
          (error nil))

    ;; these are way too slow to use with indent before aligning
    (unless (and  plsql-align-rules-list plsql-debug)
      (setq plsql-align-rules-list
            '(
              (plsql-assignment
               (regexp . "\\(\\s-*\\):=\\(\\s-*\\)")
               (group  . (1 2))
               (modes  . '(plsql-mode))
               (repeat t)
               (tab-stop  .  nil))

              (plsql-arrorw
               (regexp . "\\(\\s-*\\)=>\\(\\s-*\\)")
               (group  . (1 2))
               (modes  . '(plsql-mode))
               (repeat t)
               (tab-stop  .  nil))

              (plsql-equals ;; exclude the previous two cases
               (regexp . "\\(\\s-*[^:]\\)=\\([^>]\\s-*\\)")
               (group  . (1 2))
               (repeat t)
               (tab-stop . nil)
               (modes    . '(plsql-mode)))

              (plsql-operator ;; watch out for comments
               (regexp . "\\(\\s-*\\)[-+/]{1}\\(\\s-*\\)")
               (group  . (1 2))
               (repeat t)
               (tab-stop . nil)
               (modes    . '(plsql-mode)))

              (plsql-keywords
               (regexp . "\\(\\s-+\\)\\(in\\|default\\|number\\|varchar2\\|blob\\|raw\\)\\b")
               (group 1)
               (repeat t)
               (case-fold t)
               (tab-stop . nil)
               (modes    . '(plsql-mode)))
              )
            ))

    (put 'plsql-align-rules-list 'risky-local-variable t)
    (add-to-list 'align-c++-modes 'plsql-mode) ;; eg expression functions ...
    (add-to-list 'align-sq-string-modes 'plsql-mode)
    (add-to-list 'align-open-comment-modes 'plsql-mode)

    ;; Should we re-bind new-line-and-indent to align the current
    ;; region? That sounds expensive.
    ))

稍后在defun plsql-mode ()

(set (make-local-variable 'align-mode-rules-list) 'plsql-align-rules-list)

如何修改plsql-mode以使align正常工作?到目前为止,我最好的解决方法是使用align-regexp(灵感来自this answer):

(defun my-align ()
  ""
  (interactive)
  (align-regexp
   (region-beginning) (region-end)
   "\\(\\s-*\\):=" 1 1 nil))

这很好,除非它没有修改右侧。

作者不再使用该模式。我使用的是emacs 23.2.1。

1 个答案:

答案 0 :(得分:0)

据我所知,函数plsql-mode应该包含:

(set (make-local-variable 'indent-line-function) 'plsql-indent)
(set (make-local-variable 'indent-region-function) 'plsql-indent-region)
(set (make-local-variable 'align-mode-rules-list) plsql-align-rules-list)

由于前两个缓冲区局部变量确实是对函数的引用,因此它们的参数应该是带引号的符号。 由于第三个应该使用变量plsql-align-rules-list中包含的值,因此不应引用此变量。

HTH )插孔(