@@ -149,7 +149,7 @@ will be started to do completion."
149149
150150This should be either an absolute path to the BASH executable or
151151the 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
153153command-line completion.
154154
155155This variable is only used when creating separate processes for
@@ -354,74 +354,62 @@ returned."
354354
355355(defun bash-completion--setup-bash-common (process )
356356 " 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 ))
425413
426414; ;; Inline functions
427415
@@ -544,8 +532,7 @@ Returns (list stub-start stub-end completions) with
544532 (setq process (bash-completion--get-process)))
545533 (let* ((comp (bash-completion--parse
546534 comp-start comp-pos
547- (process-get process 'wordbreaks )
548- (process-get process 'bash-major-version )))
535+ (process-get process 'wordbreaks )))
549536 (stub-start (bash-completion--stub-start comp)))
550537
551538 (bash-completion--customize comp process)
@@ -597,16 +584,15 @@ functions adds single quotes around it and return the result."
597584 (replace-regexp-in-string " '" " '\\ ''" word nil t )
598585 " '" ))))
599586
600- (defun bash-completion--parse (comp-start comp-pos wordbreaks bash-major-version )
587+ (defun bash-completion--parse (comp-start comp-pos wordbreaks )
601588 " Process a command from COMP-START to COMP-POS.
602589
603590WORDBREAK is the value of COMP_WORDBREAKS to use for this completion,
604591usually taken from the current process.
605592
606593Returns a completion struct."
607594 (let* ((all-tokens (bash-completion-tokenize
608- comp-start comp-pos (if (>= bash-major-version 4 )
609- wordbreaks " " )))
595+ comp-start comp-pos wordbreaks))
610596 (line-tokens (bash-completion-parse-current-command all-tokens))
611597 (first-token (car line-tokens))
612598 (last-token (car (last line-tokens)))
@@ -629,9 +615,6 @@ Returns a completion struct."
629615 parsed-stub " "
630616 words (append words '(" " ))
631617 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)))))
635618 (setq stub-start (car (bash-completion-tokenize-get-range last-token))
636619 parsed-stub (bash-completion-tokenize-get-str last-token)
637620 unparsed-stub (buffer-substring-no-properties stub-start comp-pos)
@@ -1588,7 +1571,6 @@ Return the status code of the command, as a number."
15881571 (princ " Please retry\n\n " )))
15891572
15901573 (bash-completion--debug-print-info 'use-separate-processes )
1591- (bash-completion--debug-print-procinfo 'bash-major-version )
15921574 (bash-completion--debug-print 'emacs-version emacs-version)
15931575 (bash-completion--debug-print-procinfo 'completion-ignore-case )
15941576 (bash-completion--debug-print-info 'context )
0 commit comments