You're right!
あきらめかけて is a compound verb from あきらめる and かける.
あきらめかける←あきらめ(る)+かける
verb + かける means just before an action or event and
verb + かけた is not only a past tense of verb + かける but also carrying a connotation that it didn't happen actually.
So it means pretty much like 'almost' or 'nearly', I guess.
ほとんどあきらめかけてしまった means that
I was almost ready to give up.
( but I didn't give up actually.)
彼に何か言いかけたが、彼は行ってしまった。
I almost started to saying something to him, but he had gone.
(Actually I didn't say anything to him.)
酒を飲みかけたが、やめた。
I was almost about to drink alcohol, but I stopped it.
(Actually I didn't drink any.)
死にかける。
I was about to die.
(Actually I didn't die.)
I hope this helps you!