Since August 17, 2015, the solution to this answer is very simple. With the entry into force of Regulation of the European Parliament and of the Council number 650/2012, of July 4, 2012, in Spain the law corresponding to the country of residence of the deceased at the time of his death will apply as a general rule.
Even so, the last word on what legislation to invoke is the foreigner residing in Spain. If you want Spanish law to be applied, you do not have to do anything, since as we have seen it is what the current regulations establish. However, if you decide that you want your inheritance to be governed by the law of the country of your nationality, you can do so by granting a living will and communicating your wish.
This declaration in your will can be made by any foreign person residing in Spain, whatever their nationality. It is not something that only affects the countries of the European Union, so the many English people who live in Spanish territory should not suffer from the entry into force of Brexit. They will be able to choose which law to apply to their inheritance, like any person of another nationality.