summary refs log tree commit diff
path: root/Functions/Calendar
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Calendar')
-rw-r--r--Functions/Calendar/calendar7
-rw-r--r--Functions/Calendar/calendar_add29
2 files changed, 30 insertions, 6 deletions
diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar
index 328da853c..b5df2ca72 100644
--- a/Functions/Calendar/calendar
+++ b/Functions/Calendar/calendar
@@ -293,6 +293,13 @@ fi
       showline=${line%%$'\n'*}
     else
       showline=$line
+      match=()
+      # Strip continuation lines starting " #".
+      while [[ $showline = (#b)(*$'\n')[[:space:]]##\#[^$'\n']##(|$'\n'(*)) ]]; do
+	showline="$match[1]$match[3]"
+      done
+      # Strip trailing empty lines
+      showline=${showline%%[[:space:]]#}
     fi
     if (( showall || (t >= start && (remaining || t <= stop || icount < showcount)) ))
     then
diff --git a/Functions/Calendar/calendar_add b/Functions/Calendar/calendar_add
index 8e6eca8b6..dc9f50c2b 100644
--- a/Functions/Calendar/calendar_add
+++ b/Functions/Calendar/calendar_add
@@ -12,7 +12,7 @@ setopt extendedglob
 
 local calendar newfile REPLY lastline opt
 local -a calendar_entries lockfiles
-integer newdate done rstat nolock nobackup
+integer my_date done rstat nolock nobackup
 
 autoload -U calendar_{read,lockfiles,scandate}
 
@@ -42,10 +42,20 @@ if ! calendar_scandate -a "$*"; then
   print "$0: failed to parse date/time" >&2
   return 1
 fi
-(( newdate = $REPLY ))
+(( my_date = $REPLY ))
 
 # $calendar doesn't necessarily exist yet.
 
+local -a match mbegin mend
+local my_uid their_uid
+
+# Match a UID, a unique identifier for the entry inherited from
+# text/calendar format.
+local uidpat='(|*[[:space:]])UID[[:space:]]##(#b)([[:xdigit:]]##)(|[[:space:]]*)'
+if [[ "$*" = ${~uidpat} ]]; then
+  my_uid=$match[1]
+fi
+
 # start of block for following always to clear up lockfiles.
 {
   (( nolock )) || calendar_lockfiles $calendar || return 1
@@ -55,15 +65,22 @@ fi
 
     {
       for line in $calendar_entries; do
-	if (( ! done )) && calendar_scandate -a $line && (( REPLY > newdate )); then
+	if (( ! done )) && calendar_scandate -a $line && (( REPLY > my_date )); then
 	  print -r -- "$*"
 	  (( done = 1 ))
-	elif [[ $REPLY -eq $newdate && $line = "$*" ]]; then
+	fi
+	# Don't save this entry if it has the same UID as the new one.
+	if [[ -n $my_uid && $line = ${~uidpat} ]]; then
+	  their_uid=$match[1]
+	  [[ ${(U)my_uid} = ${(U)their_uid} ]] && continue
+	fi
+	if [[ $REPLY -eq $my_date && $line = "$*" ]]; then
+	  (( done )) && continue # paranoia: shouldn't happen
 	  (( done = 1 ))
 	fi
 	print -r -- $line
-	done
-	(( done )) || print -r -- "$*"
+      done
+      (( done )) || print -r -- "$*"
     } >$newfile
     if (( ! nobackup )); then
       if ! mv $calendar $calendar.old; then