@@ -149,7 +149,7 @@ will be started to do completion."
149
149
150
150
This should be either an absolute path to the BASH executable or
151
151
the name of the bash command if it is on Emacs' PATH. This should
152
- point to a recent version of BASH, 3 or 4 , with support for
152
+ point to a recent version of BASH 4 or 5 , with support for
153
153
command-line completion.
154
154
155
155
This variable is only used when creating separate processes for
@@ -354,74 +354,62 @@ returned."
354
354
355
355
(defun bash-completion--setup-bash-common (process )
356
356
" Setup PROCESS to be ready for completion."
357
- (let (bash-major-version)
358
- (bash-completion-send " complete -p" process)
359
- (process-put process 'complete-p
360
- (bash-completion-build-alist (bash-completion--get-buffer process)))
361
- (bash-completion-send " echo -n ${BASH_VERSINFO[0]}" process)
362
- (setq bash-major-version
363
- (with-current-buffer (bash-completion--get-buffer process)
364
- (string-to-number (buffer-substring-no-properties
365
- (point-min ) (point-max )))))
366
- (bash-completion-send
367
- (concat " function __emacs_complete_wrapper {"
368
- (if (>= bash-major-version 4 )
369
- " COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\" ;"
370
- " " )
371
- " eval $__EMACS_COMPLETE_WRAPPER;"
372
- " n=$?;"
373
- " if [[ $n = 124 ]]; then"
374
- (bash-completion--side-channel-data " wrapped-status" " 124" )
375
- " return 1; "
376
- " fi; "
377
- (when (>= bash-major-version 4 )
378
- (concat
379
- " if [[ -n \" ${_EMACS_COMPOPT}\" ]]; then"
380
- (bash-completion--side-channel-data " compopt" " ${_EMACS_COMPOPT}" )
381
- " fi;" ))
382
- " return $n;"
383
- " }" )
384
- process)
385
- (if (>= bash-major-version 4 )
386
- (bash-completion-send
387
- (concat
388
- " function compopt {"
389
- " command compopt \" $@\" 2>/dev/null;"
390
- " ret=$?; "
391
- " if [[ $ret == 1 && \" $*\" = *\" -o nospace\" * ]]; then"
392
- " _EMACS_COMPOPT='-o nospace';"
393
- " return 0;"
394
- " fi;"
395
- " if [[ $ret == 1 && \" $*\" = *\" +o nospace\" * ]]; then"
396
- " _EMACS_COMPOPT='+o nospace';"
397
- " return 0;"
398
- " fi;"
399
- " return $ret; "
400
- " }" )
401
- process))
402
-
403
- ; ; some bash completion functions use quote_readline
404
- ; ; to double-quote strings - which compgen understands
405
- ; ; but only in some environment. disable this dreadful
406
- ; ; business to get a saner way of handling spaces.
407
- ; ; Noticed in bash_completion v1.872.
408
- (bash-completion-send " function quote_readline { echo \" $1\" ; }" process)
409
-
410
- (bash-completion-send " echo -n ${COMP_WORDBREAKS}" process)
411
- (process-put process 'wordbreaks
412
- (with-current-buffer (bash-completion--get-buffer process)
413
- (buffer-substring-no-properties
414
- (point-min ) (point-max ))))
415
- (process-put process 'bash-major-version bash-major-version)
416
-
417
- (bash-completion-send " bind -v 2>/dev/null" process)
418
- (process-put process 'completion-ignore-case
419
- (with-current-buffer (bash-completion--get-buffer process)
420
- (save-excursion
421
- (goto-char (point-min ))
422
- (and (search-forward " completion-ignore-case on" nil 'noerror ) t ))))
423
-
424
- (process-put process 'setup-done t )))
357
+ (bash-completion-send " complete -p" process)
358
+ (process-put process 'complete-p
359
+ (bash-completion-build-alist (bash-completion--get-buffer process)))
360
+ (bash-completion-send
361
+ (concat " function __emacs_complete_wrapper {"
362
+ " COMP_TYPE=9; COMP_KEY=9; _EMACS_COMPOPT=\"\" ;"
363
+ " eval $__EMACS_COMPLETE_WRAPPER;"
364
+ " n=$?;"
365
+ " if [[ $n = 124 ]]; then"
366
+ (bash-completion--side-channel-data " wrapped-status" " 124" )
367
+ " return 1; "
368
+ " fi; "
369
+ " if [[ -n \" ${_EMACS_COMPOPT}\" ]]; then"
370
+ (bash-completion--side-channel-data " compopt" " ${_EMACS_COMPOPT}" )
371
+ " fi;"
372
+ " return $n;"
373
+ " }" )
374
+ process)
375
+ (bash-completion-send
376
+ (concat
377
+ " function compopt {"
378
+ " command compopt \" $@\" 2>/dev/null;"
379
+ " ret=$?; "
380
+ " if [[ $ret == 1 && \" $*\" = *\" -o nospace\" * ]]; then"
381
+ " _EMACS_COMPOPT='-o nospace';"
382
+ " return 0;"
383
+ " fi;"
384
+ " if [[ $ret == 1 && \" $*\" = *\" +o nospace\" * ]]; then"
385
+ " _EMACS_COMPOPT='+o nospace';"
386
+ " return 0;"
387
+ " fi;"
388
+ " return $ret; "
389
+ " }" )
390
+ process)
391
+
392
+ ; ; some bash completion functions use quote_readline
393
+ ; ; to double-quote strings - which compgen understands
394
+ ; ; but only in some environment. disable this dreadful
395
+ ; ; business to get a saner way of handling spaces.
396
+ ; ; Noticed in bash_completion v1.872.
397
+ (bash-completion-send " function quote_readline { echo \" $1\" ; }" process)
398
+
399
+ (bash-completion-send " echo -n ${COMP_WORDBREAKS}" process)
400
+ (process-put process 'wordbreaks
401
+ (with-current-buffer (bash-completion--get-buffer process)
402
+ (buffer-substring-no-properties
403
+ (point-min ) (point-max ))))
404
+
405
+ (bash-completion-send " bind -v 2>/dev/null" process)
406
+ (process-put process 'completion-ignore-case
407
+ (with-current-buffer (bash-completion--get-buffer process)
408
+ (save-excursion
409
+ (goto-char (point-min ))
410
+ (and (search-forward " completion-ignore-case on" nil 'noerror ) t ))))
411
+
412
+ (process-put process 'setup-done t ))
425
413
426
414
; ;; Inline functions
427
415
@@ -544,8 +532,7 @@ Returns (list stub-start stub-end completions) with
544
532
(setq process (bash-completion--get-process)))
545
533
(let* ((comp (bash-completion--parse
546
534
comp-start comp-pos
547
- (process-get process 'wordbreaks )
548
- (process-get process 'bash-major-version )))
535
+ (process-get process 'wordbreaks )))
549
536
(stub-start (bash-completion--stub-start comp)))
550
537
551
538
(bash-completion--customize comp process)
@@ -597,16 +584,15 @@ functions adds single quotes around it and return the result."
597
584
(replace-regexp-in-string " '" " '\\ ''" word nil t )
598
585
" '" ))))
599
586
600
- (defun bash-completion--parse (comp-start comp-pos wordbreaks bash-major-version )
587
+ (defun bash-completion--parse (comp-start comp-pos wordbreaks )
601
588
" Process a command from COMP-START to COMP-POS.
602
589
603
590
WORDBREAK is the value of COMP_WORDBREAKS to use for this completion,
604
591
usually taken from the current process.
605
592
606
593
Returns a completion struct."
607
594
(let* ((all-tokens (bash-completion-tokenize
608
- comp-start comp-pos (if (>= bash-major-version 4 )
609
- wordbreaks " " )))
595
+ comp-start comp-pos wordbreaks))
610
596
(line-tokens (bash-completion-parse-current-command all-tokens))
611
597
(first-token (car line-tokens))
612
598
(last-token (car (last line-tokens)))
@@ -629,9 +615,6 @@ Returns a completion struct."
629
615
parsed-stub " "
630
616
words (append words '(" " ))
631
617
rebuilt-line (buffer-substring-no-properties start comp-pos))
632
- (if (< bash-major-version 4 )
633
- (setq last-token (car (last (bash-completion-tokenize
634
- start comp-pos wordbreaks)))))
635
618
(setq stub-start (car (bash-completion-tokenize-get-range last-token))
636
619
parsed-stub (bash-completion-tokenize-get-str last-token)
637
620
unparsed-stub (buffer-substring-no-properties stub-start comp-pos)
@@ -1588,7 +1571,6 @@ Return the status code of the command, as a number."
1588
1571
(princ " Please retry\n\n " )))
1589
1572
1590
1573
(bash-completion--debug-print-info 'use-separate-processes )
1591
- (bash-completion--debug-print-procinfo 'bash-major-version )
1592
1574
(bash-completion--debug-print 'emacs-version emacs-version)
1593
1575
(bash-completion--debug-print-procinfo 'completion-ignore-case )
1594
1576
(bash-completion--debug-print-info 'context )
0 commit comments