File: edit

package info (click to toggle)
swi-prolog 9.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,408 kB
  • sloc: ansic: 387,503; perl: 359,326; cpp: 6,613; lisp: 6,247; java: 5,540; sh: 3,147; javascript: 2,668; python: 1,900; ruby: 1,594; yacc: 845; makefile: 428; xml: 317; sed: 12; sql: 6
file content (101 lines) | stat: -rwxr-xr-x 2,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh -f
#
# Ask PceEmacs to edit files for  me.   To  use  this package, make sure
# xpce-client is installed in  your  path   and  one  XPCE  process runs
# PceEmacs as a server. One way to do   that  is to put the following in
# your X startup:
#
#      xterm -iconic -title 'PceEmacs server' -e swipl -g emacs_server
#
# If you use the `terminator`  terminal   emulator,  consider adding the
# editor plugin from https://github.com/mchelem/terminator-editor-plugin
# and use the command ``edit  --no-wait {filepath}:{line}``. This allows
# opening  locations  reported  as  `file:line`    to  be  opened  using
# ctrl-click in PceEmacs.
#
# Author: Jan Wielemaker
# Copying: Public domain

usage()
{ echo "usage: `basename $0` [--no-wait] [+line] file[:line]"
  exit 1
}

line=""
opts="-bc"
wait=wait

HOST=`hostname`
APPCONFIG=${XDG_DATA_HOME-$HOME/.config}/swi-prolog/xpce
serverbase="$APPCONFIG/emacs_server"

case "$DISPLAY" in
  :*)	server=$serverbase.$(echo "$DISPLAY" | sed 's/^:\([0-9]*\).*/\1/')
	;;
  *)	server=$serverbase.$HOST
        ;;
esac

#echo "Server = $server"

if [ ! -S "$server" -o -z "$DISPLAY" ]; then
    server="$serverbase"
    if [ ! -S "$server" ]; then
	echo "No PceEmacs server"
	exec emacs "$*"
    fi
fi

done=false
while [ $done = false ]; do
    case "$1" in
	+[0-9]*)
		line=`echo "$1" | sed 's/^+//'`
		shift
		;;
	--no-wait)
		opts=-c
		wait=nowait
		shift
		;;
	*)
		done=true
		;;
    esac
done

file="$1"

case "$file" in
	"")	usage
		;;
	[~/]*)	;;
	*)	file=`pwd`/$file ;;
esac

case "$file" in
	*:[0-9]*:[0-9]*)
		eval `echo $file | sed 's/\(.*\):\([0-9]*\):\([0-9]*\)$/file=\1;line=\2;charpos=\3/'`
		;;
	*:[0-9]*)
		eval `echo $file | sed 's/\(.*\):\([0-9]*\)$/file=\1;line=\2/'`
		;;
esac

if [ -z "$line" ]; then
	cmd="edit('$file',[],[],$wait)"
elif [ -z "$charpos" ]; then
	cmd="edit('$file',$line,[],$wait)"
else
	cmd="edit('$file',$line,$charpos,$wait)"
fi

xpce-client $server $opts "$cmd"

if [ $? = 2 ]; then
  if [ "$line" = "" ]; then
    exec emacs "$file";
  else
    exec emacs "$file" +$line
  fi
fi