-
Notifications
You must be signed in to change notification settings - Fork 1
pipe shell command
D Groth edited this page Nov 25, 2024
·
4 revisions
With the pipe-shell-command you can call command line programs and use their output directly from within MicroEmacs.
Here an example on how to insert the primary selection into a running GUI version of MicroEmacs (mew or mews) even if you selected Clipboard only in User Setup -> System Clipboard:
; to be placed in USERNAME.emf
; replace ISO-8859-15 with your prefered ISO encoding used from within ME
define-macro insert-primary-selection
0x400 pipe-shell-command "xclip -o -selection primary | iconv -f UTF-8 -t ISO-8859-15" #l0
insert-string #l0
!emacro
!if ¬ &band $system 0x01
; GUI - non-terminal mode
global-bind-key "insert-primary-selection" "S-insert"
!endif
This is simple solution which has a 2048 byte limite for the variable content length and hardcodes the ISO conversion independent from the current character setting. Steve suggest a more general approach which has not these limitations. here his implementation:
define-macro insert-primary-selection
!if &seq &which "xclip" "ERROR"
ml-write "Error: xclip is not installed, please install!"
!return
!endif
set-position "\x82"
!force 0 delete-buffer "*ips-tmp*"
0x40 pipe-shell-command "xclip -o -selection primary" "*ips-tmp*"
buffer-mode "view"
buffer-is-utf8 #l1
!iif #l1 4 change-buffer-charset "utf8" "display"
beginning-of-buffer
set-mark
end-of-buffer
!force backward-char
copy-region
goto-position "\x82"
!force 0 delete-buffer "*ips-tmp*"
yank
!emacro