【问题标题】:How can I make the auto-complete feature in emacs match long perl variables?如何使 emacs 中的自动完成功能匹配长 perl 变量?
【发布时间】:2011-05-10 22:14:38
【问题描述】:

最好的自动完成功能是匹配单词字符。例如:自动完成将仅匹配先前使用的变量 $longvariablename[$i]{'key'} 中的 $longvariablename。我想配置自动完成或任何其他 emacs el 文件以匹配整个变量。

作为最后的手段,我将不得不学习 lisp #shudder#。

提前致谢。

【问题讨论】:

  • 不是 100% 清楚您想要哪个...您希望它一直完成到结束 } ?

标签: perl emacs autocomplete


【解决方案1】:

您可以自定义hippie expand

例如,以下自定义将所有字符串扩展为空格或分号。

(defun try-expand-perl-extended-var (old)
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'perl-extended-var-search))
    (unwind-protect
        (try-expand-dabbrev old)
      (fset 'he-dabbrev-search old-fun))))


(defun perl-extended-var-search (pattern &optional reverse limit)
  (let ((result ())
    (regpat (concat (regexp-quote pattern) "[^ ;]+")))
    (while (and (not result)
        (if reverse
             (re-search-backward regpat limit t)
             (re-search-forward regpat limit t)))
      (setq result (buffer-substring-no-properties (save-excursion
                                                     (goto-char (match-beginning 0))
                                                     (skip-syntax-backward "w_")
                                                     (point))
                           (match-end 0)))
      (if (he-string-member result he-tried-table t)
      (setq result nil)))     ; ignore if bad prefix or already in table
    result))

不要忘记将您的自定义函数包含到make-hippie-expand-function 列表中

(global-set-key [(meta f5)] (make-hippie-expand-function
                               '(try-expand-perl-extended-var
                                 try-expand-dabbrev-visible
                                 try-expand-dabbrev
                                 try-expand-dabbrev-all-buffers) t))

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2011-08-05
    • 2012-07-27
    相关资源
    最近更新 更多