Nothing contained in this chapter shall be construed to restrain the power of any court to issue a writ of habeas corpus when necessary to bring before them any prisoner for trial, in any criminal case lawfully pending in the same court, or to bring any prisoner to be examined as a witness in any action or proceeding, civil or criminal, pending in such court, when they think the personal attendance and examination of the witness necessary for the attainment of justice.
NMS § 44-1-36