Charge-density waves, incommensurate modulations and superconductivity in phosphorus and iodine