Get and set the contents of a string in an emacs buffer programmatically

I would like to translate the following function from a vim script to emacs elisp (I use it to set email recipients when writing emails).

My question basically is how to get and set the contents of the string in emacs, because with a quick search in googling I could not find this (maybe I just did not know the correct conditions for google for, "getline" and "setline" in any case showed any results).

function! G_set_to()  
    let address = system('my-address-script')  "shell command to choose addresses  
    let line = getline (2)  
    if strlen(line) == 4  
        call setline(2,  line . address)  
    else  
        call setline(2,  line . "; " . address)  
    endif  
endfunction  

Sorry if the answer is obvious, I'm completely new to emacs and don’t even know how to use the built-in help system.

Cheers Arian

+3
source share
2 answers

, G-address-script .

(require 'sendmail)
(defvar G-address-script "echo hi@google.com")
(defun G-set-to ()
  "execute script in G-address-script and populate the To: line with the results"
  (interactive)
  (save-excursion
    (mail-to)
    (unless (= (current-column) 4)
      (insert "; "))
    (insert (shell-command-to-string G-address-script))
    (when (looking-at "^$") ; when shell command has extra newline, delete it
      (delete-backward-char 1))))

, Emacs lisp . :

  • C-h i (control-h, i, , Emacs Emacs Lisp.
  • M-x apropos
  • C-h f
  • C-h v
  • *scratch* C-j ()
  • M-x edebug-defun, emacs lisp, , (M-x eval-defun )
  • M-x eldoc-mode emacs lisp , .
+3

, :

(defvar G-address-script "goobook_dmenu_with_cache")  
  (defun G-set-to ()  
    "execute script in G-address-script and populate the To: line with the results"  
    (interactive)  
    (save-excursion  
  (goto-line 2)  
  (re-search-forward "$")  
  (unless (= (current-column) 4)  
    (insert "; "))  
  (insert (shell-command-to-string G-address-script))))

:

  • , Trey , , G-address- script, , , ?
  • ?
  • / ? vim script , , - .

, , , Trey , . !

+1

Source: https://habr.com/ru/post/1756356/


All Articles