2017-05-08 63 views
0

我正在編寫簡單的elisp函數,它交互地使用3個參數:from,to和separator。然後,它把一系列數字:Emacs交互式讀取轉義序列

(defun gen-seq (from to sep) 
    "Generates sequence of numbers FROM .. TO with separator SEP" 
    (interactive "nFrom: \nnTo: \nMSeparator: ") 
    (insert (mapconcat 'number-to-string (number-sequence from to) sep))) 

但當sep\n,它會產生類似

1\n2\n3\n4\n5\n6\n7\n8\n9\n10 

是否有可能實現數字列在我的Emacs緩衝這個功能呢?

+0

切圓,你可能會發現[微型](https://github.com/abo-abo/tiny)庫出於興趣。 – phils

回答

1

您可以輸入C-q C-j作爲分隔符輸入換行符。有關詳細信息,請參閱emacs手冊中的Inserting Text

1

尼克的答案是進入新行的標準方法,但如果你真的想Emacs在閱讀字符串參數,就好像它是一個elisp的引用字符串,你可以這樣做:

(defun gen-seq (from to sep) 
    "Generates sequence of numbers FROM .. TO with separator SEP" 
    (interactive "nFrom: \nnTo: \nMSeparator: ") 
    (let* ((sepesc (replace-regexp-in-string "\"" "\\\\\"" sep)) 
     (sepnew (car (read-from-string (concat "\"" sepesc "\""))))) 
    (insert (mapconcat 'number-to-string (number-sequence from to) sepnew)))) 

你可以還使用(interactive "x")閱讀的說法,除了用戶需要輸入雙引號:"\n"