在emacs-lisp中,如何在文本字符串中间定位点?

时间:2014-02-06 03:25:19

标签: emacs lisp elisp

在emacs-lisp中,如何将点放在文本字符串的中间?我希望我的光标在%s处于以下函数的位置:

(defun web-research ()
(interactive)
(insert "#+BEGIN_QUOTE\n\n%s\n#+END_QUOTE\n")
(org-mac-chrome-insert-frontmost-url)
)

2 个答案:

答案 0 :(得分:2)

有很多选择。 例如,

(defun web-research ()
  (interactive)
  (insert "#+BEGIN_QUOTE\n\n%s\n#+END_QUOTE\n")
  (search-backward "%")
  (org-mac-chrome-insert-frontmost-url))

(defun web-research ()
  (interactive)
  (insert "#+BEGIN_QUOTE\n\n")
  (let ((p (point)))
    (insert "\n\n#+END_QUOTE\n")
    (org-mac-chrome-insert-frontmost-url)
    (goto-char p))

(defun web-research ()
  (interactive)
  (insert "#+BEGIN_QUOTE\n\n%s")
  (save-excursion (insert "\n#+END_QUOTE\n"))
  (org-mac-chrome-insert-frontmost-url))

IMO第二个是最好的。

答案 1 :(得分:0)

你可以使用yasnippet这样的东西。

# -*- mode: snippet -*-
# name: web-research
# expand-env: ((yas-indent-line 'fixed))
# key: wr
# --
#+BEGIN_QUOTE

%s$0

#+END_QUOTE
`(if (boundp 'org-mac-chrome-get-frontmost-url) (org-mac-chrome-get-frontmost-url) "http://www.example.com/")`

我似乎没有org-mac-chrome-get-frontmost-urlinsert变体,但经过快速搜索后,我猜测org-mac-chrome-get-frontmost-url是与此解决方案一起使用的东西。