[Question]
  [
In this challenge you will be given a list of positive integers which represents some range of integers which has been truncated for display. Your job is to find the missing bits and insert ellipses to show that that part has been truncated.
The input will always be strictly ascending and if two consecutive values differ by more than 1 then we know some data has been removed in between them.
For example if the input is:
```
1,2,3,4,20,21,22
```
Then since `4` and `20` differ by more than 1 we insert an ellipsis between them:
```
1,2,3,4,...,20,21,22
```
However if the consecutive values differ by *exactly two*, then we just reinsert the missing value (their mean), since an ellipsis doesn't actually save any space when it's just covering 1 value.
So for example if the input is:
```
1,2,3,5,6
```
Then `3` and `5` differ by more than 1 so data has been removed between them, but they differ by 2 so we just insert the missing `4`.
```
1,2,3,4,5,6
```
Additionally if the first value is greater than `1` we know that something has been truncated off the front. So we add an ellipsis, or if the first value is `2`, a `1` as the first value. We can't know that something has been truncated off the end so we never add anything there.
## Task
Given a list of positive strictly-ascending integers as input output the list with the proper insertions. You can represent ellipses in the output as any constant value other than a positive integer. For the convenience of strongly typed programming, you may also output a list of optional values with the null value representing ellipses.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the goal is to minimize the size of your source code as measured in bytes.
## Test cases
```
[1,2,3,4,20,21,22] -> [1,2,3,4,...,20,21,22]
[1,2,3,5,6] -> [1,2,3,4,5,6]
[2,3,4,9] -> [1,2,3,4,...,9]
[3,5,7,8,10] -> [...,3,4,5,6,7,8,9,10]
[1,20,23] -> [1,...,20,...,23]
```
  
[Answer]
# JavaScript (ES10), ~~45~~ 43 bytes
Uses `undefined` for ellipses.
```
a=>a.map(p=v=>[[[],v-1][v+~p],p=v]).flat(2)
```
[Try it online!](https://tio.run/##bY3LDsIgEEX3fgnEKSlTnwv6I5NZTGoxGizENiz9dcS4ZXdzz308Jcs6vR9p65Z4m4t3Rdwo5iVJJZfdSEQMubNMef9JDNVkbXyQTaEuU1zWGGYT4l15RRYQBjgA9oBVI2u9a0aOcGqwf/naIL/GGS5g@/Zk/RsqKV8 "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>             // a[] = input array, e.g. [ 1, 3, 6 ]
  a.map(p =      // initialize p to a zero'ish value
  v =>           // for each value v in a[]:
    [            //   build an array:
      [          //     according to v - p - 1, append:
        [],      //       an empty array if it's 0
        v - 1    //       v - 1 if it's 1
                 //       implicitly: undefined for anything else
      ][v + ~p], //
      p = v      //     append v and update p to v
    ]            //   end of array
  )              // end of map(); this gives:
                 //   [ [ [], 1 ], [ 2, 3 ], [ undefined, 6 ] ]
  .flat(2)       // apply .flat() at depth 2 to clean this up:
                 //   [ 1, 2, 3, undefined, 6 ]
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 24 bytes
```
,/0{((0;();x-1)x-y),x}':
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs9LRN6jW0DCw1tC0rtA11KzQrdTUqahVt+LiSlMwVDBSMFYwUTAyUDACso3gQqYKZkA2RNISyAKJmCtYKBgaQJQA1RsDAHV1EeY=)
Uses `0N` for ellipses.
## Explanation
* `0{...}':` pairwise map with placeholder 0 (*y* is prev elem, *x* is next elem)...
	+ `(0;();x-1)x-y` get elem of list `(0;();x-1)` at index *x* - *y*
	+ `,x` append *x*
* `,/` flatten
[Answer]
# [R](https://www.r-project.org), ~~69~~ 68 bytes
*Edit: -1 byte thanks to pajonk*
```
\(x){F[i<-cumsum(2-!(j=diff(c(0,x))-1))]=x;F[-i]=(x*(j<2))[j>0]-1;F}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMHaxJSUkozUpJzEvOxi26WlJWm6FjddYjQqNKvdojNtdJNLc4tLczWMdBU1smxTMtPSNJI1DHQqNDV1DTU1Y20rrN2idTNjbTUqtDSybIw0NaOz7AxidQ2t3WohZt1iZES2AajbUMdIx1jHRMfIQMcIyAbqUVBW0LVTiIZJ6OnpwSVjubDqNtUxw9AGFMNQDZGxxGqFJYZqkLnmOhY6hgZwDSCFUMPBUpZASWxuAjrXGMkWqBfAlHEsJCQWLIDQAA)
Uses `-1` as the ellipsis character.
**How?**
```
j=diff(c(0,x))-1    # get the differences between adjacent elements -1
!j                  # zero for consecutive integers, 1 otherwise
i=cumsum(2-!j)      # indices of original elements, leaving gaps for ellipses or new elements-in-gaps
F[i]=x              # fill-in the elements into vector F
F[-i]=              # fill-in the gaps with...
      (x...)[j>0]-1 # one less than the subsequent original value...
        *(j<2)      # ...adjusted to zero if the gap was >2
F                   # finally, return F
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~22~~ ~~19~~ ~~17~~ 15 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
0šüŸε¦¤®s‚‚éн}˜
```
Uses `-1` for ellipsis, but could alternatively use another 1-byte alternative (e.g. `0`, `""`, `" "`, `"\n"`, `"abcdefghijklmnopqrstuvwxyz"`, etc.) by replacing the `®`.
-3 bytes porting [*@MamaFunRoll*'s K (ngn/k) answer](https://codegolf.stackexchange.com/a/249628/52210)  
-2 bytes porting [*@DominicVanEssen*'s Husk answer](https://codegolf.stackexchange.com/a/249636/52210)  
-2 bytes thanks to *@CommandMaster* with yet another different approach
[Try it online](https://tio.run/##yy9OTMpM/f/f4OjCw3uO7ji39dCyQ0sOrSt@1DALiA6vvLC39vSc//@jjXSMdUx1LHUMjWMB) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeV/g6MLD@85uuPc1kPLDi05tK74UcMsIDq88sLe2tNz/uv8j4421DHSMdYx0TEy0DECso1idaBCpjpmQDZE0hLIAomY61joGBpAlADVG0MVmOpY6hiCOEC5WAA).
**Explanation:**
```
          #  Example input: [2,3,5,9,13]
0š        # Prepend a 0 to the (implicit) input-list
          #  STACK: [0,2,3,5,9,13]
  ü       # For each overlapping pair {a,b}:
   Ÿ      #  Push a list in the range [a,b]
          #   STACK: [[0,1,2],[2,3],[3,4,5],[5,6,7,8,9],[9,10,11,12,13]]
ε         # Map over each inner list:
          #   STACK1: [0,1,2] ;        STACK2: [5,6,7,8,9]
 ¦        #  Remove the first item
          #   STACK1: [1,2] ;          STACK2: [6,7,8,9]
  ¤       #  Push the last item (without popping the list)
          #   STACK1: [1,2],2 ;        STACK2: [6,7,8,9],9
   ®      #  Push -1, the ellipsis value
          #   STACK1: [1,2],2,-1 ;     STACK2: [6,7,8,9],9,-1
    s     #  Swap the top two values on the stack
          #   STACK1: [1,2],-1,2 ;     STACK2: [6,7,8,9],-1,9
     ‚    #  Pair them together
          #   STACK1: [1,2],[-1,2] ;   STACK2: [6,7,8,9],[-1,9]
      ‚   #  Pair the two lists together
          #   STACK1: [[1,2],[-1,2]] ; STACK2: [[6,7,8,9],[-1,9]]
       é  #  Sort by length (shortest to longest)
          #   STACK1: [[1,2],[-1,2]] ; STACK2: [[-1,9],[6,7,8,9]]
        н #  Pop and leave the first inner list
          #   STACK1: [1,2] ;          STACK2: [-1,9]
}         # After the map
          #  STACK: [[1,2],[3],[4,5],[-1,9],[-1,13]]
 ˜        # Flatten the resulting list of lists
          #  STACK: [1,2,3,4,5,-1,9,-1,13]
          # (after which the result is output implicitly)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 62 bytes
```
lambda a:sum([[~-i*(i-2in[0]+a),i][i-1in[0]+a:]for i in a],[])
```
[Try it online!](https://tio.run/##bY7PDoIwDMbvPsUSL5t2BDb/QeKTzB5mDLGJDIJ48OKrT4YLKPHU9vt@/drm2V1rp315PPmbrc4Xy2xxf1TcmJekFSepyJkU11YAoSGZxbHAsm4ZMXLMIhgUvmnJdbzkJgMFGjagUlB9r1AItmSjnCTJZC1mW1vYzfCgTNRHy/9E5l9UyNnDAbI0ggGIYYORB@vndv@QHlPji0PR6N8 "Python 3 – Try It Online")
Use `0` for ellipses.
For each value `i` in input:
* If `i - 1` is already included in input, or `i - 1` is `0`, we need insert nothing before it;
* Otherwise, if `i - 2` is already included in input, or `i - 2` is `0`, we need insert `i - 1` before it;
* Otherwise, we insert `...` before it.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
```
##&[Pick[#>p+2||++p,p<#],p=#]&/@(p=0;#)&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X1lZLTogMzk7WtmuQNuopkZbu0CnwEY5VqfAVjlWTd9Bo8DWwFpZU@1/QFFmXkm0sq5dmgNQoi44OTGvrpqr2lDHSMdYx0THyEDHCMg2qtWBiZnqmIE4EGlLEBMkZq5joWNoAFUF1GNcy1X7HwA "Wolfram Language (Mathematica) – Try It Online")
Represents ellipses by `True`.
```
##&[Pick[#>p+2||++p,p<#],p=#]&/@(p=0;#)&
                                 p=0    starting from 0,
                              /@(   ;#) for each element:
         #>p+2                            True if current-previous>2,
              ||++p                         otherwise previous+1,
    Pick[          ,p<#]                      but omit if =current
##&[                    ,p=#]           prepend and update previous
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 11 bytes
```
ŻṖ‘ż¹FQµIỊa
```
[Try it online!](https://tio.run/##y0rNyan8///o7oc7pz1qmHF0z6GdboGHtno@3N2V@P9w@9FJD3fO0Iz8/z/aUMdIx1jHRMfIQMcIyDaK1YEKmeqYAdkQSUsgCyRirmOhY2gAUQJUbxwLAA "Jelly – Try It Online")
`0` for ellipses.
```
Ż              Prepend a 0,
 Ṗ             trim the last element,
  ‘            increment,
   ż¹F         flat-interleave with the original input,
      Q        and uniquify.
       µ  a    Zero out any elements of the result which
        I      have a difference with the next element
         Ị     greater than 1.
```
[Answer]
# [Haskell](https://www.haskell.org), 69 bytes
```
g x y|x+1==y=[y]|x+2==y=[x+1,y]|True=[0,y]
f a=concat$zipWith g(0:a)a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=VZBNbsIwEIXVRTc-xSxYEDFIjmkhQfKSExSJRZSFlZLEgvwocQSpehM2bFDPVE7DJKnbdOX3vXl-Gs3lK1X1YX88Xq-3xsRz73uTwBnaz_PMlbKVQRuSFL0kCwm3VbOXASfJYlAyKvJImcmHLnfapJBM-Vo5aii7Pz0bkBAwAJgGLgpc4AsKjoK0CBF-Pf7nOjiOv-JynOvQBgbH_1_jj_9T5WIY9_092nFXvUIPXd4luG3vPb9znZAxTdtnqoS4NmBY8UN1_k7EKjsEzVimdE5cNubNVDCBOi1O9FBGQjFcw574AQ)
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 50 bytes
```
a->b=0;concat([if(c-b<3,[b+1..b=c],[x,b=c])|c<-a])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY1dCsIwEISvEvqU4KY0qT8Vm14kBNkEUgqlhlJBwZv4UhDxTN7GhNanmfl2h3l-Ao7duQ3zyxP1vk6eV1-JvLGqOLnL4HCiuvPUcVuXoO1G5LlVzoC-QVL2cDVHw9ZmiyH0d4qENySM3TBFm6WQEU-RMSBaC5BQwhZkATJ6aSJc2A72KSznY7KJHaACUaxfsVOa_9w8L_oD)
Use `x` for ellipses.
[Answer]
# [Perl 5](https://www.perl.org/) + `-p -M5.10.0`, 35 bytes
If using a `0` is acceptable this would be 31 bytes, but that feels a bit cheaty...
```
$;=$_*say$--1?"...":$_-1if$-=$_-1-$
```
[Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiJDs9JF8qc2F5JC0tMT9cIi4uLlwiOiRfLTFpZiQtPSRfLTEtJCIsImFyZ3MiOiItcFxuLU01LjEwLjAiLCJpbnB1dCI6IjNcbjVcbjdcbjlcbjEwIn0=)
[Answer]
# [Python 2](https://docs.python.org/2/), 57 bytes
```
p=1
for n in input():
 if p<n:print-~p/n*p
 print n;p=n+1
```
[Try it online!](https://tio.run/##RYzLCsIwEEX3@YpLVz5GbFKf0X6JdCUpDZTpUCLqxl@PSRWFGZhzHyPP0A1s4r3zvYO27uGuRVFEqbVqhxEMn0duYTa3Cr6FnNnK6DmsXrLmhShMBD5JzUsdJ1L5x0UTDKEibNJRps2CadTf2BJ2iX@pY4KPvCccCLr8pnO7at4 "Python 2 – Try It Online")
A program that takes in a list on STDIN and prints the output values on separate lines.
[Answer]
# [J](http://jsoftware.com/), 34 31 bytes
```
0(}.(+_*_1>])2-/\])@~.@,<:,@,.]
```
[Try it online!](https://tio.run/##Vcw9DsIwDAXgvaewWJrAq0lSfqNSRSAxIQZmog6ICrFwgvbqIS0UlcGS/fzZzzDhtKadpZRAimysjOlwOR2DEg2LWTWtdOmlyeZXL13LDoWFA/sgk/OeSTXWNeyE6KguvFRoTdb@dKSllQ6@118VTcOyZxpjmCT32@NFNWkY5FjAKJjYm/98idUQfNh2GLvdGhtoNbqIP/LwBg "J – Try It Online")
This was surprisingly difficult to golf in J and the K approach ended up being longer than either of these.
## Idea
We take a two pass strategy:
* First we insert the numbers below each number.
* Then we check if there are any gaps greater than 1. If so, we replace those gaps with infinity `_`.
## How
Consider `2 3 4 9`:
* `<:...,.]` Decrement zipped with original input:
```
1 2
2 3
3 4
8 9
```
* `0...~.@,...,@` Flatten, prepend 0, and take the unique:
```
0 1 2 3 4 8 9
```
* `}.(...)2-/\]` On the left hand side, kill the 0, on the right hand side take consecutive deltas:
```
1 2 3 4 8 9  (...) _1 _1 _1 _1 _4 _1 
```
* `_*_1>]` Turn every entry less than \_1 on the right into infinity:
```
0 0 0 0 _ 0
```
* `+` And add that to the left side:
```
1 2 3 4 _ 9
```
## [J](http://jsoftware.com/), first approach, 34 bytes
```
[:;]<@~.@,~"+]+_3>.@%@+3<.2-~/\0,]
```
[Try it online!](https://tio.run/##bY1LCsIwEED3nmIoaBMzjenEb40SFFyJC7c1RBCLuPEGvXpMLYUWXAzze/PmHRKZVrArIAUEBUWMTMLxej6Fstg6Y2tpsU6EE17vpR1boY2krJ7dFLrAR5eDBMdEQ5U8@Qf9EHNnJup4TNZzK5nP@0zrGT7MIkJM@ClNDLedbPR8vD5QQY6EGudICinWNJwvcNkNWmzTtc1uhWvMVe8iOnT4Ag "J – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 15 bytes
```
Gɾ‡?cḊƛḢ[h?c∧;f
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBUCIsIiIsIkfJvuKAoT9j4biKxpvhuKJbaD9j4oinO2YiLCIiLCJbMSwyLDMsNCwyMCwyMSwyMl1cblsxLDIsMyw1LDZdXG5bMiwzLDQsOV1cblszLDUsNyw4LDEwXVxuWzEsMjAsMjNdIl0=)
Uses `0` for ellpisis.
[Answer]
# [Brainfuck](https://github.com/TryItOnline/brainfuck), 71 bytes
```
,[[->+>+<<]>>[-<<+>>]<<<[->-<]+>-[-[<<.>-]<[>>-.+<<-<]>]<[-<]>>[-]>.>,]
```
[Ungolfed program](https://ato.pxeger.com/run?1=ZZExbsMwDEXRlaf4YwJFNuKpA6GLGB7cREaMNrIhyajTubfokqVDr9TTlLbspEUBQRLFx0-K_Ph68nXrmuHwfL1-DrHRj98P77QjKonyPEeItY8BnUM8WTj7isOp9uLWRhnFXJExYjArYypi5smj5ZkMEZe6UvMuFPRYEtoGR7QBrovYEyEh80FYoT9Ugc09QnaPYisIcya4VNj71kW8Wd_Jq6yRdcWE0vzSKeRudKYY-S1iRP8yBJHciOQF59ZN1jYpcCXfokne22Ajoj334V-1QtCSb0q3ZtsT-jqExZmkpggy2b3gi5i71GPrjnOHb90VlNIwlpmss_kB) (a port of my Haskell solution)
[Script to test it](https://ato.pxeger.com/run?1=lVJLTsQwDJXYkVMYhmVauUm_A-qGY6BZdPphKkRThVaaBcdgx2YWcClOg5O0DIgpEl448Xt-tmPl9W1bPO0Oh_dxaLz04-xlBXcBF1zykAvkgu5iA15-RH3fPzLsKz3i8c88AxjaRdnvIpmljTLhKQ_QZRhmkls8M8zUhrrKuc40hj3khrFGaWi7fhzIAwYoUGIoUARCzGGEMTgcM7BxgikWRFOevIZKsfO63Cm4coWeYb-vwNPg9XS_2eqi7ZqxfPDabqh1r2vy-Xe81-peF4-5U7JKdTWj0W-V1nU5gBoHKrsGgnCytZ3NDBMSJhDsvCfNNwYXl0tq87pls2p_sTMt5H9aRAm0xwgwxgRojbTRYlF7ojU9FY2TfzQ2cvBXzH3O6Y_Of_UT)
[Answer]
# [Rust](https://www.rust-lang.org), ~~135~~ 130 bytes
*-5 bytes thanks to @alpehalpha*
```
|v:Vec<i8>|v.iter().scan(0,|c,&a|Some((match a-*c{1=>vec![a],2=>vec![a-1,a],_=>vec![-1,a]},*c=a).0)).flatten().collect::<Vec<_>>()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bVFLTsMwEBXbnmLaBbKraZSkfNq0CYdAYoOiyDJOieQ6VeJGSEk2XINNkeAC3AZOg5OUUGhnYc_4vTdvbL-8Zdtc7z5iBWuWKEKhlELDCvz3rY4ns8_nqvDuBF8ms6AqrESLjFAr50wRGyuO56y6TdeCkDXT_BHYZMxLxw8KwYf3LET3J504aMpoX7ZVjWPuM2rZlFqxZFoLY2_xVErBtectG9coCAjtJvk6e10MBmAiTjMgWuQ64iwXCOJpYxTiISqY3AoKiYLWpSU3QdrSQReneIGuja7J3RAQ_gBmqh6jeFJ9iVdHsubsiN5B81Me82N20_gaZ-jYvcAQ981bZN5gp4YyA08PXLo7NOs0pC07hLJXbbJEaamGZFR6N_UIYfX7jhaXqRKEUrro-SzPRaaH5IBGwff_v3gnqAd191O7Xbd_Aw)
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~16~~ 14 bytes
*Edit: -2 bytes by stealing [Kevin Cruijssen's improvements](https://codegolf.stackexchange.com/a/249629/95126) in his port of this!*
```
ΣẊö◄LSeoe0→t…Θ
```
[Try it online!](https://tio.run/##ATIAzf9odXNr///Oo@G6isO24peETFNlb2Uw4oaSdOKAps6Y////WzIsMyw0LDE4LDE5LDIwXQ "Husk – Try It Online")
Uses `0` for ellipsis; could use any other integer by exchanging the `0` at position 10 in the code.
```
             Θ     # add a zero at the start of the list; 
 Ẋȯ                # now, for every pair of elements:
            …      #  fill gaps with numeric ranges,
           t       #  and discard the first element,
     Se            #  then make a 2-element list of this and
       oe0→        #  just the last element preceded by zero,
   ◄L              #  and select the element with minimum length;
Σ                  # finally, flatten the resulting list-of-lists.  
```
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~76~~ 71 bytes
```
p;f(*a,n){for(p=0;n--;)printf("%d %d "+(++p==*a)*3,p+1<*a?0:p,p=*a++);}
```
[Try it online!](https://tio.run/##hVTRbqMwEHzvV1hIlTAYldjQXuJyfaj6FSU6IWJ6qI2DAtJFF/HrRx1sbMe1riiJzc7s7uxu7DqpPyr@Nk0dbcKoQhyem8Mx7IqU8iShsDu2fGjC4HYHxCeIwzjuiiKqYERQF68eo@op3XSoE6Y4hnScBB3sq5aHEJxvgHguhoH1w6/V6xYU4LxCGBGUIZwiLPZ4pIaCbUqO7m2MSEw6r20kk8jF4wH9QKvUBnMdUuQjI100RTPcS1TqQ0qEWolaM7XmxlkauHTu27/s0IQyBrxTr5F6R8DGsYNjBycOThw8c/DMwXMHz6Elmp06Vg9s504idWehifiaaCaiGcQNtXYZajrpEmGe0dpMSRP1pGY97rQWmiSZUpCl1toTa59Z@9zXj@tBmtimmZZNN9zk9fCwh0c8POLhZR5e5uHlHp4eeH3g/QDq39UxEr@sfmdHWWVQnl5weVo/i28eIGC/k0B5izsAhJcetXzHTsItpWr76Mr4KgJSEMczG87B5D1gzp0IJ8/ezNlSGwZcoWIoPriftWiT0ak0Cn18Tg815/L0caFvsv52J8punwIQbAKxG17bLTQhFx5IfoLAsosThgCH9LoYJvLqv6ZP8N4ieGpaspX8RZE211k9BfYgAfeeIrXy7wLs/@P8pT3M356Sl3zJM96M07@6@aje@in58wk "C (clang) – Try It Online")
*Saved 5 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!!!*
Inputs a pointer to an array of positive integers and its length (because pointers in C carry no length info).  
Prints out the filled in array using \$0\$ for ellipses.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~50~~ 45 bytes
```
->l{a=0;l.map{|x|p x-a<2?a:0if x>a+=1;p a=x}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6nOtHWwDpHLzexoLqmoqZAoUI30cbIPtHKIDNNocIuUdvW0LpAIdG2orb2P1dadLShjpGOsY6pjpmOZWwsV4GCujpI1AiJbRwb@x8A "Ruby – Try It Online")
Thanks Jonah for -2 bytes and a different approach which saved 3 more bytes.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 44 bytes
```
{d=$0-a;if(d>1)print d==2?$0-1:0;print a=$0}
```
[Try it online!](https://tio.run/##SyzP/v@/OsVWxUA30TozTSPFzlCzoCgzr0QhxdbWyB4obGhlYA0RSQSqqv3/35jLlMuMy5LL0IDL0IjL0JjLyOBffkFJZn5e8X/dskRbAwA "AWK – Try It Online")
*Thanks to [Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen) for pointing out that 5 bytes needed to initialize the variable `a` on TIO aren't needed on GNU awk, and so shouldn't count in the score.*
Outputs 0 for `...`.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 17 bytes
*Inspired by Arnauld's [JavaScript answer](https://codegolf.stackexchange.com/a/249624/65425)*
```
.n,Le<[YtdG)aZ=Zd
```
[Try it online!](https://tio.run/##K6gsyfj/Xy9PxyfVJjqyJMVdMzHKNirl//9oQx0jHRMdIwMdIyDLKBYA "Pyth – Try It Online") or [Try all test cases](https://tio.run/##K6gsyfivbBtl8F8vT8cn1SY6siTFXTMxyjYqJVDB1vX//2hDHSMdYx0THSMDHSMg2yiWCypkqmMGZEMkLYEskIi5joWOoQFECVC9cSwA "Pyth – Try It Online")
Uses the lowercase alphabet as the ellipsis (could alternatively use `0` or empty string).
```
.n,Le<[YtdG)aZ=Zd
                    Implicitly initialize Z to 0
   L                Left map over the input with variable d
      [    )        3-element list of...
       Y              ... the empty list
        td            ... (d - 1)
          G           ... the lowercase alphabet
     <              Keep the first N elements of that list, where...
            aZd      ... N = the absolute difference of Z and d
              =Zd   (Set Z to d)
    e               Take the last element of the resulting list
  ,                 Create a two-element list of (result, current element)
.n                  Flatten
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 73 bytes
```
\d+
$*
^
,
(^|\b1+),(?=11\1\b)
$&1$1,
(^|\b1+),(?=11\1)
$&...,
^,
1+
$.&
```
[Try it online!](https://tio.run/##Zcw9DoMwFAPg3edIUSBWhAP9G6qOXCKKKCoDS4eqY@@eJmLs9uzPeu/1s70e@WCnOceng@mQQNj0jYtcS3u/SVFxaWEaGf1TBe89kQiofPBNzmLgwJGhZyh3wF4cecIOV9R05oXqK5bd8AM "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
\d+
$*
```
Convert to unary.
```
^
,
```
Prefix `0` (in unary).
```
(^|\b1+),(?=11\1\b)
$&1$1,
```
Where two consecutive integers differ by `2`, insert the missing integer.
```
(^|\b1+),(?=11\1)
$&...,
```
Where two consecutive integers differ by more than `1`, insert an ellipsis.
```
^,
```
Remove the leading `0`.
```
1+
$.&
```
Convert to decimal.
[Answer]
# [R](https://www.r-project.org), 75 bytes
```
\(x,y=c(0,x))for(i in x-1){if(!i%in%y)show(`if`((i-1)%in%y,i,0));show(i+1)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhY3vWM0KnQqbZM1DHQqNDXT8os0MhUy8xQqdA01qzPTNBQzVTPzVCs1izPyyzUSMtMSNDQygVJgQZ1MHQNNTWuwVKa2oWYt1MjvaRrJGoY6RjrGOiY6RgY6RkC2EVBhcmKJhlJMnpKmsoKunUI0TIWenh5cVSwXQq-pjhluTUBJiFoI1xK_8ZYQtSAzzXUsdAwNMJWDlEENBquxBKqCuwboOmNsNkCdDqaMYyHeX7AAQgMA)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
ＩＥ⊕Φ⌈θ№⁺θ⊖θ⊕ι∧№⊞Ｏ⁺θ⊕θ¹ιι
```
[Try it online!](https://tio.run/##TYzNCsIwEIRfpccNrGARUfAkFcGD2HvpIaQLDeSn3STi28dYRDswl5n5Ro2SlZcm55a1i9DIEOEuJ7g5xWTJRRrgqk0kLvFL22RhFlg1PpV1a1KAGasL/cezKPWa1kJ8orMb4EulMD4mYhk9/y7WxHJRF@vFRaecu26HezzgEett3@fN07wB "Charcoal – Try It Online") Link is to verbose version of code. Uses `0` to represent an ellipsis. Explanation:
```
     θ                      Input array
    ⌈                       Maximum
   Φ                        Filter on implicit 0-indexed range
        θ                   Input array
       ⁺                    Concatenated with
          θ                 Input array
         ⊖                  Vectorised decrement
      №                     Contains
            ι               0-indexed value
           ⊕                Incremented (i.e. 1-indexed)
  ⊕                         Incremented (back to 1-indexed values)
 Ｅ                          Map over values
                  θ         Input array
                 ⁺          Concatenated with
                    θ       Input array
                   ⊕        Vectorised increment
               ⊞Ｏ           Concatenated with
                     ¹      Literal integer `1`
              №             Contains
                      ι     Current value
             ∧              Logical And
                       ι    Current value
Ｉ                           Cast to string
                            Implicitly print
```
]