就地字/符号Dabbrev扩展

时间:2011-12-08 22:11:25

标签: emacs autocomplete expansion abbreviation

这是我对dabbrev-expand的扩展,以支持子字符串扩展。据我所知,它按预期工作。但是,如果它支持 in-symbol 扩展,类似于mdabbrev的行为,我会发现它更有用,顺便说一句,它在符号字符和大小写方面是不完整的 - 调整支持。然而,pattern的{​​{1}}参数只是点之前的模式,但对于就地扩展,我们需要点之后的模式。为什么在hippie / dabbrev-expand中没有这种模式,是否有一种首选方式来查询它?

dabbrev-substring-search

,例如使用

激活
(defun dabbrev-substring-search (pattern &optional reverse limit syntax-context)
  "Expand dabbrev substring. See:
http://www.emacswiki.org/cgi-bin/wiki/HippieExpand#toc5"
  (let ((result ())
        (regpat (cond ((not hippie-epxand-dabbrev-as-symbol)
                       (concat (regexp-quote pattern) W*))
                      ;; ((eq (char-syntax (aref pattern 0)) ?_)
                      ;;  (concat (regexp-quote pattern)
                      ;;          "\\(\\sw\\|\\s_\\)*"))
                      (t
                       (concat "\\(?:"
                               Y<
                               "\\(" "\\(?:\\sw\\|\\s_\\)+" "\\)"
                               "\\(" (regexp-quote pattern) "\\)"
                               "\\(" "\\(?:\\sw\\|\\s_\\)*" "\\)"
                               Y>
                               "\\)"

                               "\\|"

                               "\\(?:"
                               Y<
                               "\\(" "\\(?:\\sw\\|\\s_\\)*" "\\)"
                               "\\(" (regexp-quote pattern) "\\)"
                               "\\(" "\\(?:\\sw\\|\\s_\\)+" "\\)"
                               Y>
                               "\\)"

                               )))))
    (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

    (when nil
      (when result
        (let* ((p (point))
               (end3 (match-end 3))
               (beg2 (match-end 2))
               (end2 (match-end 2))
               (dummy (message "%s %s %s" end3 beg2 end2))
               (beg (- end3 beg2))       ;begin offset from point
               (end (- end3 end2)))      ;end offset from point
          (setq dabbrev-substring-match-region (cons beg end))
          (hictx-generic (- p beg) (- p end) nil 'match 3))))

    result))
;; Use: (dabbrev-substring-search "he")

(defun try-expand-dabbrev-substring-visible (old)
  "Like `try-expand-dabbrev' but for visible part of buffer."
  (interactive "P")
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
    (unwind-protect (try-expand-dabbrev-visible old)
      (fset 'he-dabbrev-search old-fun))))

(defun try-expand-dabbrev-substring (old)
  "Like `try-expand-dabbrev' but for substring match."
  (interactive "P")
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
    (unwind-protect (try-expand-dabbrev old)
      (fset 'he-dabbrev-search old-fun))))

(defun try-expand-dabbrev-substring-all-buffers (old)
  "Like `try-expand-dabbrev-all-buffers' but for substring match."
  (interactive "P")
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
    (unwind-protect (try-expand-dabbrev-all-buffers old)
      (fset 'he-dabbrev-search old-fun))))

1 个答案:

答案 0 :(得分:0)

这可能会或可能没有帮助。与普通的dabbrev一样,它与点之前的文本一起使用,但候选匹配除了前缀之外还可以是子字符串,正则表达式或模糊(各种类型)。 Icicles - Dynamic Abbreviation