victorhge / iedit

Modify multiple occurrences simultaneously
https://www.emacswiki.org/emacs/Iedit
402 stars 43 forks source link

iedit does not register variables in bash/sh mode #134

Closed jakob1379 closed 2 years ago

jakob1379 commented 3 years ago

I have the following script, do not mind what is going on, but when I try to iedit-mode on the section variable only the declarations are found and the expansion on line 29. I would expect the last one to get caught as variable expansions are normally registered by iedit.

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

lines=$(grep -P "^\w+.*=" config.ini)
section=""

declare -A config

# echo "found variables and values"
# for line in $lines; do

#     value=$(echo "$line" | awk -F '=' '{print $2}')
#     config[$index]="$value"
#     # echo "$index: $value"
# done

while read -r line; do
    if [[ "$line" =~ ^\[.*\]$ ]]
    then
    section=$(echo "$line" | tr --delete '\[\]')
    elif [[ "$line" =~ ^# ]]
    then
    continue
    echo "COMMENT: $line"
    else
    index=$(echo "$line" | awk -F '=' '{print $1}')
    value=$(echo "$line" | awk -F '=' '{print $2}')
    config[$section/$index]="$value"
    fi
done < config.ini

using emacs 27.2, iedit 20210203.23 from melpa

victorhge commented 2 years ago

I am afraid this cannot be fixed inside of Iedit. "/" is symbol in the syntax table of shell script mode. There are several workarounds:

  1. Add (setq iedit-use-symbol-boundaries nil) to your sh-mode-hook
  2. Modify the syntax table by (modify-syntax-entry ?/ "." sh-mode-syntax-table).
  3. Mark 'section' first then enable iedit-mode